专业编程基础技术教程

网站首页 > 基础教程 正文

C++模拟ATM自动取款机 atm取款机c++代码

ccvgpt 2024-11-03 13:22:07 基础教程 7 ℃

想要一起学习C++的可以加群248894430,群内有各种资料满足大家

C++模拟ATM自动取款机 atm取款机c++代码

/*

C++模拟ATM自动取款机

功能:1.进行密码验证,3次输入密码的机会

2.显示业务菜单

3.选择相应菜单进行业务处理

*/

#include <iostream> //输入输出流头文件

#include <string>//字符串头文件

using namespace std;

int main()

{

string strPassword;//用户密码

int iChoose, iCount = 0; //iCount用户输入密码的次数

//1.进行密码验证,3次输入密码的机会

cout << "欢迎使用ATM自动取款机" << endl; //end line

cout << "请输入您的密码:";

cin >> strPassword;//获取用户输入的密码

while (strPassword != "123456")

{

//密码错误

if (++iCount == 3) //++iCount 返回iCount自增之后的值,iCount++返回iCount自增之前的值

{

//已经输入3次错误密码

cout << "3次密码错误,系统退出。" << endl;

return -1; //退出主函数

}

else

{

//没有达到3次输入

cout << "密码错误,请重新输入:";

//fflush(stdin); //清空输入缓存区 standard input stream

cin.ignore(100, '\n');

cin >> strPassword;

}

}

cout << "您输入的密码是:" << strPassword << endl;

cout << "密码正确,请选择您要办理的业务:" << endl;

cout << "\t1.存款\n\t2.取款\n\t3.查询\n\t4.退出" << endl;

while (!(cin >> iChoose) || iChoose < 1 || iChoose > 4)

{

cout << "您选择的业务编号有误,请重新选择:";

cin.clear(); //清除cin的错误状态

cin.sync(); //清除输入缓存区

}

switch (iChoose)

{

case 1:

cout << "请将您的钞票放入存款口中,按确认开始存款!" << endl;

break;

case 2:

cout << "请输入您要取款的金额!" << endl;

break;

case 3:

cout << "您当前的余额为5000000元人民币!" << endl;

break;

case 4:

cout << "谢谢使用ATM自动取款机,再见!" << endl;

break;

}

return 0;

}

想要一起学习C++的可以加群248894430,群内有各种资料满足大家

Tags:

最近发表
标签列表