My C/C ++ path-007 class (imitating the ATM withdrawal Program)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.