简易的实现了ATM的工作流程
代码逻辑并不多,主要是对循环的使用,而且做的比较简易,任然有些bug未去解决
代码如下:
int main()
{
int choice = 0;
int password = 123;
int scanpwd = 0;
int money = 1000000;
int chance = 3;
int Imoney = 0;
printf("*******************\n");
printf("欢迎光临\n");
printf("*******************\n请输入密码:");
while (1){
scanf("%d",&scanpwd);
if (scanpwd == password) {
break;
}else{
chance--;
if (chance > 0){
printf("*******************\n");
printf("输入密码错误,请重新输入,您还有%d次机会\n",chance);
printf("*******************\n");
printf("请重新输入密码:");
}else{
printf("*******************\n");
printf("输入错误次数达到上限,账号也被冻结,请到柜台解锁\n");
exit(EXIT_FAILURE);
}
}
}
while (1){
printf("*******************\n");
printf("1.取款\n");
printf("2.存款\n");
printf("3.更改密码\n");
printf("4.退出\n");
printf("*******************\n");
printf("请选择功能:");
while (1){
scanf("%d",&choice);
if (choice > 0&&choice < 5){
break;
}
else {
printf("请输入正确的序号:");
}
}
switch (choice){
case 1:
printf("请输入取款金额:");
scanf("%d",&Imoney);
money = money - Imoney;
while (1){
if (money > 0) {
printf("取款成功,余额:%d\n", money);
break;
}else{
printf("余额不足\n");
break;
}
}
break;
case 2:
printf("请输入存款金额:");
scanf("%d",&scanpwd);
money = money + scanpwd;
printf("存款成功,余额为:%d\n",money);
break;
case 3:
printf("请输入原密码:");
scanf("%d",&scanpwd);
if (scanpwd == password){
printf("请输入新密码:");
scanf("%d", &scanpwd);
password = scanpwd;
printf("请确认新密码:");
scanf("%d", &scanpwd);
if (scanpwd == password){
printf("密码更改成功!!!\n");
password = scanpwd;
}else{
printf("两次密码不一致,请重新设置密码\n");
}
}else{
printf("密码错误!!!\n");
}
break;
case 4:
exit(EXIT_SUCCESS);
default:
break;
}
}
return 0;
}
以上的代码能够简易的实现ATM机的工作流程,嗯,,,重点是简易
代码测试内容如下:
代码测试
网友评论