#include<stdio.h> #include<stdlib.h> int x;//保存客户ID(index值) void login(); //登录 void menu(); //菜单 void deposit(); //存款 void withdraw();//取款 void check(); //查询 void quit(); //退卡 struct User { char name[10]; int account; short password; int money; } user[4]={ {"Tom",1,1,400}, {"Mike",2,2,700}, {"Jake",3,3,500}, {"Helen",4,4,800}, }; void main(){ printf("***********欢迎使用取款机系统************\n"); printf("***************************************\n"); login(); } void login () { int a; int account; short password; printf("Please Enter Your Account ID:"); scanf("%d",&account); for(a=0;a<=9;a++) //遍历user[] { if(account==user[a].account) { x=a; printf("Please Enter Your Pssword:"); scanf("%d",&password); if(password==user[x].password) { printf("*********Welcome %s*******\n",user[x].name); printf("***********************\n"); printf("Please Selsct Operation NUM:"); menu(); break; } else { printf("Wrong Password\n"); login(); } } } } void menu() { int n; int operatorNum=0; printf("\nCheck************1\n"); printf("Withdraw*********2\n"); printf("Deposit**********3\n"); printf("Quit*************4\n"); while(operatorNum!=4) { printf("Please Select Operation NUM:"); scanf("%d",&n); switch(n) { case 1:check();break; case 2:withdraw();break; case 3:deposit();break; case 4:quit();break; default:printf("Wrong operator\n"); } } } //查询 void check() { printf("%s Your balance is %d RMB:\n",user[x].name,user[x].money); } //取款 void withdraw() { int a; printf("Pease Enter Amount:"); scanf("%d",&a); if(a>user[x].money) printf("Sorry InSufficient Balance!\n"); else { user[x].money=user[x].money-a; printf("You have take %d RMB,Your balance is %d RMB\n",a,user[x].money); } } // 存款 void deposit() { int a; printf("Pease Enter Amount:"); scanf("%d",&a); user[x].money=user[x].money+a; printf("You have deposited %d RMB, Your balance is %d RMB\n",a,user[x].money); } // 退卡 void quit() { system("cls"); // 清屏 main(); //返回主页面,从新登录 }
原文地址:http://www.cnblogs.com/thrive/p/3863726.html