#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
int password = 123456;
int balance = 100000;
char operation;
int wrongTime = 1;
int inputedPassword;
int z = 0; //状态值
while (1) {
printf("****************\n");
printf("1.输入密码\n2.取款\n3.查询余额\n4.更改密码\n5.退出\n");
printf("****************\n");
printf("选一个吧:");
scanf("%c", &operation);
while (operation < ‘1‘ || operation > ‘5‘) {
printf("别搞笑,好好输:");
getchar();
scanf("%c", &operation);
}
switch (operation) {
//1.输入密码
case ‘1‘:
printf("密码是啥:");
scanf("%d", &inputedPassword);
while (wrongTime < 3 && inputedPassword != password) {
printf("别骗我!\n你还有%d次机会:", 3 - wrongTime);
scanf("%d", &inputedPassword);
wrongTime++;
}
if (inputedPassword == password){
//正确
printf("****************\n");
printf("\n输对了,牛逼啊!\n \n");
printf("****************\n");
z = 1;
} else{
//次数过多
printf("****************\n");
printf("错多了!狗带吧!\n");
printf("****************\n");
exit(EXIT_SUCCESS);
}
getchar();
break;
//2.取款
case ‘2‘:
if (z == 1) {
while(1) {
int totalMoney;
int num2_1;
printf("****************\n");
printf("1.¥100\n2.¥300\n3.¥500\n4.其他金额\n");
printf("****************\n");
scanf("%d", &num2_1);
if (num2_1 == 1) {
totalMoney = 100;
}else if (num2_1 == 2){
totalMoney = 300;
}else if (num2_1 == 3){
totalMoney = 500;
}else if (num2_1 == 4){
printf("取多少:");
scanf("%d", &totalMoney);
}else {
printf("别搞笑,好好输\n");
continue;
}
if (totalMoney <= balance) {
balance -= totalMoney;
printf("\n您的余额为:%d\n \n", balance);
}else {
printf("\n穷B,钱不够!\n \n");
}
printf("****************\n");
printf("1.继续取款\n2.任意数字键退出\n");
printf("****************\n");
int num2_2;
scanf("%d", &num2_2);
if (num2_2 == 1) {
continue;
}else {
break;
}
}
}
printf("大兄弟,输密码先!");
getchar();
break;
//3.查询余额
case ‘3‘:
if (z == 1) {
printf("你还有¥%d\n", balance);
}else{
printf("大兄弟,输密码先!");
}
getchar();
break;
//4.更改密码
case ‘4‘:
if (z == 1) {
printf("输入新密码:\n");
scanf("%d", &password);
}else{
printf("大兄弟,输密码先!");
}
getchar();
break;
//5.退出
case ‘5‘:
printf("拔卡!拔卡!拔卡!\n");
exit(EXIT_SUCCESS);
default:
break;
}
printf("\n");
}
return 0;
}