| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6370 人关注过本帖
标题:自己写的ATM模拟程序
取消只看楼主 加入收藏
chymzjy1
Rank: 1
等 级:新手上路
帖 子:21
专家分:4
注 册:2011-10-6
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:2 
自己写的ATM模拟程序
我是一个初学C语言的,今天写了一个ATM模拟程序!有什么问题的话请各位指点一下!

#include<stdio.h>
#include<time.h>
#include<windows.h>
#define clear system("cls")
#define p 3800000
#define N 19
int a,b,c,i,j,g,t;

void gotoxy(int x,int y) //输出定位子函数
{
     COORD c;
     c.X=x-1;
     c.Y=y-1;
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}

void delay(int z)       //延时子函数,延时时间为1ms
{
     int m,n;
     for(m=z;m>0;m--)
      for(n=110;n>0;n--);
}

void over()     //结束模块
{
     clear;
     gotoxy(28,13);
     printf("本次交易结束,请取卡!");
     delay(p);
}

void progressbar()        //进度条模块
{
    clear;
    gotoxy(31,13);
    printf("请稍候");
    for(c=0;c<10;c+=2)
    {
         gotoxy(38+c,13);
         printf("*");
         delay(380000);
    }
}

void balance()
{
     clear;
     gotoxy(30,12);
     srand(time(0));
     t=rand()%100000000;
     printf("您的余额是%d元!",t);
}

int homepage()        //主页
{
    clear;
    gotoxy(30,10);
    printf("=========================");
    gotoxy(31,11);
    printf("1 取款业务   2 余额查询");
    gotoxy(31,13);
    printf("3 转账业务   4 退出系统");
    gotoxy(30,14);
    printf("=========================");
    gotoxy(30,15);
    printf("请输入相应业务选项:");
    scanf("%d",&j);
    switch(j)
    {
        case 1:getmoney();break;
        case 2:
               {
                 clear;
                 printf("正在查询");
                 progressbar();
                 gotoxy(30,14);
                 balance();
                 gotoxy(30,14);
                 system("pause");
               };break;
        case 3:
               {
                 clear;
                 gotoxy(34,13);
                 printf("业务暂不支持!");
                 delay(p);
                 progressbar();
               };break;
        case 4:
             {
               progressbar();
               over();
               progressbar();
               main();
             };break;
        default:homepage();break;
    }
    homepage();
}

int getmoney()
{
    clear;
    gotoxy(30,12);
    progressbar();
    clear;
    gotoxy(30,9);
    printf("=====================");
    gotoxy(31,10);
    printf("1 100元     2 200元");
    gotoxy(31,12);
    printf("3 300元     4 400元");
    gotoxy(31,14);
    printf("5 自定义    6 返回 ");
    gotoxy(30,15);
    printf("=====================");
    gotoxy(30,16);
    printf("请输入相应选项:");
    scanf("%d",&a);
    clear;
    gotoxy(30,13);
    progressbar();
    clear;
    gotoxy(21,13);
    switch(a)
    {
        //出钞票的时候不知道弄成什么效果,所以以一句话代替了!
        case 1:printf("您的钞票100元已经出来,请点清……");break;
        case 2:printf("您的钞票200元已经出来,请点清……");break;
        case 3:printf("您的钞票300元已经出来,请点清……");break;
        case 4:printf("您的钞票400元已经出来,请点清……");break;
        case 5:
            {
             printf("请输入您要取出的数目:");
             scanf("%d",&b);
             clear;
             gotoxy(21,13);
             progressbar();
             clear;
             if(b%100==0&&b>99)
               {
                 if(b<=10000)
                   {
                      clear;
                      gotoxy(21,13);
                      printf("您的钞票%d元已经出来,请点清……",b);
                   }
                   else
                   {
                       clear;
                       gotoxy(21,13);
                       printf("您好,您要取的现金数太大,请您前往柜台办理!");
                   }
               }
             else
                 {
                  clear;
                  gotoxy(15,13);
                  printf("您输入错误,所输入的钱数必须为100的整数倍,请重新输入!");
                 }
            };break;
        case 6:homepage();break;
        default:
                {
                  clear;
                  gotoxy(35,13);
                  printf("您输入错误!");
                };break;
    }
     delay(p);
     delay(p);
     getmoney();
     getch();
}

int main()   //主程序
{
   while(1)
   {
       if(g<3)
       {
           clear;    //清屏
           gotoxy(20,12);
           printf("===========================================");
           gotoxy(21,13);
           printf("请插入您的卡,并输入密码,完成后请按确认!");
           gotoxy(20,14);
           printf("===========================================");
           gotoxy(33,15);
           printf("密码:");
           scanf("%d",&i);
           clear;
           gotoxy(30,12);
           progressbar();
           switch(i)
           {
           case 3531627:homepage();break;
           default:
                   {
                     clear;
                     gotoxy(30,13);
                     printf("密码错误,请重新输入!");
                     clear;
                     gotoxy(30,13);
                     printf("您还有%d次机会!",2-g);
                     ++g;
                     delay(p);
                   };break;
            }
       }
       else
       {
           clear;    //清屏
           gotoxy(20,13);
           printf("对不起,您已错误输入三次,今天被暂停使用!");
           delay(p);
           delay(p);
       }
    }
}

搜索更多相关主题的帖子: include system C语言 
2011-10-20 16:39
chymzjy1
Rank: 1
等 级:新手上路
帖 子:21
专家分:4
注 册:2011-10-6
收藏
得分:0 
回复 2楼 LeafC
是啊,我现在刚学C语言不久,程序中有些效果我是在网上找的!
2011-10-21 08:29
chymzjy1
Rank: 1
等 级:新手上路
帖 子:21
专家分:4
注 册:2011-10-6
收藏
得分:0 
回复 4楼 smallmoon521
很谢谢你的建议,没想到一个sleep()用起来这么简单的!我这个程序的延时是参照单片机里的!
2011-10-21 08:31
快速回复:自己写的ATM模拟程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.079823 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved