你還在為現(xiàn)實(shí)中囊中羞澀的窘境而感到窘迫嗎?還在為ATM中少的可憐的存款而感到擔(dān)憂嗎,是否想讓你ATM中的存款數(shù)字的小數(shù)點(diǎn)向右移動(dòng)幾位,想不想足不出戶體驗(yàn)ATM的存款金額中小數(shù)點(diǎn)以前數(shù)零都數(shù)不過來的快感,也就是所謂的一夜暴富正常情況下一般是

不過不用擔(dān)心,程序猿有特別的解決技巧,滿足你的幻想,在虛擬而又簡陋的ATM系統(tǒng)中體驗(yàn)存款爆棚的快感
通往虛擬百萬富豪道路
Step 1
清楚如何用for循環(huán)產(chǎn)生死循環(huán)的效果:通常情況下,for循環(huán)一般由自定義的循環(huán)變量,應(yīng)該滿足的條件,和變量的變化情況組成
如for(int i = 0;i<8;i++)
{ }執(zhí)行順序?yàn)樽兞抠x初始值,判斷是否滿足條件,執(zhí)行代碼的語句,變量發(fā)生變化,然后再進(jìn)行判斷,再進(jìn)行代碼塊內(nèi)語句的執(zhí)行,然后變量產(chǎn)生變化,直到變量不在滿足條件為止。特殊情況下,變量賦初始值和變量自身發(fā)生的變化可省略,只留下條件判斷;
故而可以用for(;1<2;)來制造死循環(huán),必要時(shí)用break跳出
Step 2 明白siwtch語句的用處
ATM取款時(shí)一般存在多個(gè)操作選項(xiàng),存款,取款,查詢余額,修改密碼,和退出系統(tǒng)等操作,專業(yè)的銀行ATM機(jī)用觸屏式而這里改用scanf輸入式
Step 3
由于涉及到多次輸入數(shù)據(jù),必要時(shí)需要使用getchar()來接受緩存區(qū)里存在的換行符\n 或直接用fflush(stdlin)清除緩存區(qū)里的所有數(shù)據(jù)
#include<stdio.h>
#include<stdlib.h>
int main(){
int password =12345; //原本的密碼
int input; //輸入的密碼
int wrongTime =3; 最多的輸入次數(shù)
printf("***********************************************************\n");
printf(" Welcome to Chinese Bank systerm \n");
printf("***********************************************************\n"); //模范開頭
printf("Please enter your password: ");
for(int i = 1;i<=wrongTime; i++){
scanf("%d",&input);
if(input==password)
break;
printf("Your password is wrong,please enter it again \n");
if(i==wrongTime)
{
printf("The times that you are wrong are too many Please found the worker");
return 1;} //密碼保護(hù)措施
}
//1存款,2取款,3更改密碼,4查詢余額,5退出
int leaftmoney = 10000; //你的存款,隨心所欲的設(shè)計(jì)讓你體驗(yàn)如王思聰般富二代的快感
for(;1<2;) {
printf("*********************\n");
printf("1存款 2取款\n");
printf("3更改密碼 4查詢余額\n");
printf("5退出\n");
printf("**********************\n"); //初始界面
printf("Please make your choice :"); //鍵盤版人機(jī)操作頁面
int choice; //做出你想在銀行干什么
scanf("%d",&choice);
switch(choice){ 通過switch語句用鍵盤建立你與ATM的demon操作界面
case 1:
printf("please put in the money in the right direction");
int putin;
scanf("%d",&putin);
leaftmoney+=putin;
printf("your leaft money is %d",leaftmoney); //隨心所欲的存款金額,讓你告別沒錢的煩惱
break;
case 2:
int bringmoney;
printf("please choose how much money you want?");
for(;1<2;){
scanf("%d",&bringmoney);
if(bringmoney<=leaftmoney)
{
leaftmoney-=bringmoney;
printf("your leaft money is %d",leaftmoney);
break;}
if(bringmoney>leaftmoney)
{
printf("your leaftomney is not enough,please do it again");
}
}
break;
//想拿多少就拿多少,這個(gè)demon里,馬云馬化騰都沒你有錢
case 3:
int changecode;
int origincoedl;
int entertime;
for(entertime = 0;entertime<=3;entertime++)
{
printf("Please enter your password");
scanf("%d",&changecode);
if(changecode==password){
printf("Your password is right");
break;
}else
printf("Your enter word is wrong Please do it again");
if(entertime == 3){
printf("The times that you are wrong are too many,please call for workers for help");
exit(EXIT_FAILURE);}
} //更改密碼,讓銀行的ATM的小demon更加具有真實(shí)感
int newcode;
int checkcode;
for(;1<2;){
printf("Please make your new password\n");
scanf("%d",&newcode);
printf("please check your code is right");
scanf("%d",&checkcode);
if(checkcode==newcode){
password=newcode;
printf("your code has already changed");
break;
}if(checkcode!=newcode)
printf("please do it again");
}
break;
case 4:
printf("Your leaft money is %d\n",leaftmoney);
break;
//查看余額,你可以隨心所欲的浸泡再你的幻想金額中,無拘無束
default:
exit(EXIT_SUCCESS);
break;
}
for(;1<2;)
{
printf("Do you want to continue?\n Please make your own choice y or n \n");
getchar();
char go;
scanf("%c",&go);
if(go == 'y')
break;
if(go == 'n')
return 1;
printf("Your order is wrong please do it again");
}
printf("Thanks for using,pay attention to the security of your ground");
}
return 0;
}
如此,你可以隨心所欲的設(shè)計(jì)自己的初始金額,任意的存儲(chǔ)金額,隨性所欲的取款金額,體驗(yàn)代碼帶來的小快樂