注:转账判断账号那一步还有瑕疵。
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
int choice, i, j, r, transNum, enterID, enterPW, remitID, userRemit;
int userInfo[100][2] = {{12, 123}, {13, 123}};
double userCurrent[100] = {1000.00,1500.00};
double userInput, userOutput;
void pwJudge();
int menu();
int current();
int input();
int output();
int remit();
//主函数main/
int main(void) {
int choice = -1;
while (1) {
printf("\t\t\t欢迎使用XX银行ATM机\n");
printf("\t1.登录\n"); ///pwJudge
printf("\t2.退出\n"); ///exit退出程序
scanf("%d", &choice);
switch (choice) {
case 1:
system("cls");
pwJudge();
break;
case 2:
system("cls");
exit(0);
break;
default:
system("cls");
printf("\t\t\t输入有误,请重新输入\n");
Sleep(3000);
break;
}
}
}
/进入主菜单menu///
int menu() {
int choice = -1;
while (1) {
printf("\t\t\t迎使用XX银行ATM机\n");
printf("\n");
printf("\t\t\t请选择服务类型\n");
printf("1.查询\n"); //current
printf("2.存款\n"); //input
printf("3.汇款\n"); //remit
printf("4.取款\n"); //output
printf("5.切换账号\n");
printf("5.退出\n");//exit退出程序
scanf("%d",&choice);
switch (choice) {
case 1 :
system("cls");
current();
break;
case 2 :
system("cls");
input();
break;
case 3 :
system("cls");
remit();
break;
case 4 :
system("cls");
output();
break;
case 5 :
system("cls");
return 0;
break;
case 6 :
system("cls");
exit(0);
default:
system("cls");
printf("输入有误!请重新输入");
Sleep(1000);
system("cls");
break;
}
}
}
密码判断pwJudge
void pwJudge() {
if (r > 2) {
system("cls");
printf("\t\t\t账号或密码已错3次,正在退出\n");
Sleep(2000);
exit(0);
}
for (j = 0; 1; j++) {
printf("\t\t\t请输入账号:");
scanf("%d", &enterID);
printf("\t\t\t请输入密码:");
scanf("%d", &enterPW);
for (i = 0; i <= 10; i++) {
if ((userInfo[i][0] == enterID) && (userInfo [i][1] == enterPW)) {
system("cls");
menu();
Sleep(1000);
}
}
r++;
}
}
查询userCurrent
int current() {
printf("\t\t\t您的余额为:%.2lf", userCurrent[i]);
Sleep(2000);
system("cls");
}
//存钱input
int input() {
printf("请输入您要存入的金额:");
scanf("%lf", &userInput);
printf("您的当前金额为:%.2lf", (userCurrent[i] += userInput));
Sleep(3000);
system("cls");
}
//取钱output
int output() {
printf("请输入您要取出的金额:");
scanf("%lf", &userInput);
printf("您的当前金额为:%.2lf", (userCurrent[i] -= userInput));
Sleep(3000);
system("cls");
}
/汇款remit///
int remit() {
printf("您的当前余额为%.2lf\n", userCurrent[i]);
printf("请输入要汇款的账户名:");
scanf("%d", &remitID);
for (transNum = 0; transNum < 100; transNum++) {
if (remitID == userInfo[transNum][0]) {
break;
}
}
printf("请输入汇款金额(小于当前余额):");
scanf("%d", &userRemit);
userCurrent[i] -= userRemit;
userCurrent[transNum] += userRemit;
printf("您的当前余额为%.2f\n", userCurrent[i]);
Sleep(3000);
system("cls");
}