1 #include <stdio.h> 2 3 #include <stdlib.h> 4 5 6 7 8 9 int main(int argc, const char * argv[]) { 10 11 12 13 int password = 123456; 14 15 int balance = 100000; 16 17 char operation; 18 19 int wrongTime = 1; 20 21 int inputedPassword; 22 23 int z = 0; //状态值 24 25 while (1) { 26 27 printf("**************** "); 28 29 printf("1.输入密码 2.取款 3.查询余额 4.更改密码 5.退出 "); 30 31 printf("**************** "); 32 33 printf("选一个吧:"); 34 35 scanf("%c", &operation); 36 37 while (operation < '1' || operation > '5') { 38 39 printf("别搞笑,好好输:"); 40 41 getchar(); 42 43 scanf("%c", &operation); 44 45 46 47 } 48 49 switch (operation) { 50 51 //1.输入密码 52 53 case '1': 54 55 printf("密码是啥:"); 56 57 scanf("%d", &inputedPassword); 58 59 60 61 while (wrongTime < 3 && inputedPassword != password) { 62 63 printf("别骗我! 你还有%d次机会:", 3 - wrongTime); 64 65 scanf("%d", &inputedPassword); 66 67 wrongTime++; 68 69 } 70 71 if (inputedPassword == password){ 72 73 //正确 74 75 printf("**************** "); 76 77 printf(" 输对了,牛逼啊! "); 78 79 printf("**************** "); 80 81 z = 1; 82 83 } else{ 84 85 //次数过多 86 87 printf("**************** "); 88 89 printf("错多了!狗带吧! "); 90 91 printf("**************** "); 92 93 exit(EXIT_SUCCESS); 94 95 } 96 97 getchar(); 98 99 break; 100 101 //2.取款 102 103 case '2': 104 105 if (z == 1) { 106 107 while(1) { 108 109 int totalMoney; 110 111 int num2_1; 112 113 printf("**************** "); 114 115 printf("1.¥100 2.¥300 3.¥500 4.其他金额 "); 116 117 printf("**************** "); 118 119 scanf("%d", &num2_1); 120 121 if (num2_1 == 1) { 122 123 totalMoney = 100; 124 125 }else if (num2_1 == 2){ 126 127 totalMoney = 300; 128 129 }else if (num2_1 == 3){ 130 131 totalMoney = 500; 132 133 }else if (num2_1 == 4){ 134 135 printf("取多少:"); 136 137 scanf("%d", &totalMoney); 138 139 }else { 140 141 printf("别搞笑,好好输 "); 142 143 continue; 144 145 } 146 147 if (totalMoney <= balance) { 148 149 balance -= totalMoney; 150 151 printf(" 您的余额为:%d ", balance); 152 153 }else { 154 155 printf(" 穷B,钱不够! "); 156 157 } 158 159 printf("**************** "); 160 161 printf("1.继续取款 2.任意数字键退出 "); 162 163 printf("**************** "); 164 165 int num2_2; 166 167 scanf("%d", &num2_2); 168 169 if (num2_2 == 1) { 170 171 continue; 172 173 }else { 174 175 break; 176 177 } 178 179 180 181 } 182 183 } 184 185 printf("大兄弟,输密码先!"); 186 187 getchar(); 188 189 break; 190 191 192 193 //3.查询余额 194 195 case '3': 196 197 if (z == 1) { 198 199 printf("你还有¥%d ", balance); 200 201 }else{ 202 203 printf("大兄弟,输密码先!"); 204 205 206 207 } 208 209 getchar(); 210 211 break; 212 213 //4.更改密码 214 215 case '4': 216 217 if (z == 1) { 218 219 printf("输入新密码: "); 220 221 scanf("%d", &password); 222 223 }else{ 224 225 printf("大兄弟,输密码先!"); 226 227 } 228 229 getchar(); 230 231 break; 232 233 //5.退出 234 235 case '5': 236 237 printf("拔卡!拔卡!拔卡! "); 238 239 exit(EXIT_SUCCESS); 240 241 default: 242 243 break; 244 245 } 246 247 printf(" "); 248 249 250 251 } 252 253 return 0; 254 255 }