It's nice to have money to copy the ATM below !!!
After you enter the correct password, you can: withdraw money, deposit, and exit.
[Cpp]
# Include <stdio. h>
/*
Imitate ATM withdrawal Program
*/
Int strCompare (char *, char *);
Int accountVerify ();
Void accountOperate ();
Void simulateOfATM ()
{
If (accountVerify ())
AccountOperate ();
Printf ("GOODBYE \ n ");
}
// If you do not use the built-in strcmp, write it for fun.
Int strCompare (char * str1, char * str2)
{
While (* str1 & * str2 & (* str1 = * str2 ))
// While (* str1! = '\ 0' & * str2! = '\ 0' & (* str1 = * str2) // This low efficiency is easy to understand.
{
Str1 ++;
Str2 ++;
}
Return * str1-* str2;
}
// Pass verification www.2cto.com
Int accountVerify ()
{
Char password [50]; // I do not believe that your password has exceeded 50, but you have seen it in 30.
Char pwd [10] = {"abc "};
Int pwdCount = 0; // Number of password input records, which cannot exceed 3
Do {
Printf ("please input your password or press ENTER to break: \ n ");
Gets (password );
If (! StrCompare (password, "\ 0 ")){
Break;
}
If (strCompare (password, pwd) {// The password is incorrect.
Printf ("password error !!! \ N ");
PwdCount ++;
}
Else
{
Return 1;
}
} While (pwdCount <3 );
If (pwdCount> = 3)
Printf ("input count has outnumber, good bye !! \ N "); // The input exceeds the limit.
Else printf ("GOODBYE \ n ");
Return 0;
}
// Account operation
Void accountOperate ()
{
Int operate, initMoney = 100; // initial account value: 100
Int oprateMoney = 0; // operation amount
Do {
Printf ("the amount of your card is: % d \ n", initMoney );
Printf ("************* account operate ***************** \ n ");
Printf ("* 1: get money * \ n ");
Printf ("* 2: deposite * \ n ");
Printf ("* 3: exit * \ n ");
Printf ("************************************* * \ n ");
Printf ("please select a operate :");
Scanf ("% 1d", & operate );
Switch (operate)
{
Case 1:
Printf ("how much whowould you like to get :");
Scanf ("% d", & oprateMoney );
If (oprateMoney <= 0 | oprateMoney> initMoney) // if the input amount is less than or equal to 0 or greater than the account balance
{
Printf ("incorrect input or insufficient balance !! \ N ");
Continue;
}
InitMoney-= oprateMoney;
Printf ("¥ % d is spitting money. Please smile ......... \ N ", oprateMoney );
Continue;
Case 2:
Printf ("how much whowould you like to put :");
Scanf ("% d", & oprateMoney );
InitMoney + = oprateMoney;
Printf ("press any key to go back ");
Continue;
Case 3:
Default:
Return;
}
} While (1 );
}
From mzlqh's column