将前面的功能显示部分使用swtich语句写。
#include<iostream>
#define PASSWORD 199109
using namespace std;
//void show ( );
//void getmima (int *p);
int is_correct();
void show_func();
void function( int number);
int main(void)
{
// int mima[6];
int cnt;
int func;
// show(); //显示“您好!欢迎使用ATM,请输入6位密码
// getmima (mima) ; //获取密码值,并显示
cnt=0;
while(! is_correct())
{
cnt++;
if(cnt==3)
{cout<<"密码已输入错误三次,账户已锁定,24时小时内不得使用!"<<endl;
return 0;
}
}
show_func(); // 显示对应的功能;
cout<<"请输入功能号:";
cin>>func;
function(func); //根据对应功能号选择对应功能
while(1) ; //让画面定格住
return 0;
}
/******************************************
void show ( )
{
cout<<"您好!欢迎使用BBT自动取款机!!"<<endl;
cout<<"请输入您的密码:";
}
void getmima (int *p)
{
int i;
for(i=0; i<6; i++)
{
cin>>p[i];
}
p[i]='\0';
}
**************************************************/
int is_correct()
{
int password;
cout<<"请输入密码:";
cin>>password;
cout<<endl;
if(password!=PASSWORD)
{
cout<<"错误,请重新输入!"<<endl;
return 0;
}
else
return 1;
}
void show_func()
{
int number_func;
cout<<"功能选项:"<<endl;
cout<<"1.查询"<<endl;
cout<<"2.取款"<<endl;
cout<<"3.存款"<<endl;
cout<<"4.转账"<<endl;
cout<<"0.退出"<<endl;
}
void function( int number)
{
switch(number)
{
case 1:
cout<<"你的余额还有30000元!"<<endl;
break;
case 2:
cout<<"土豪,整个银行的都是你的!"<<endl;
break;
case 3:
cout<<"亲,随意存,多多益善!"<<endl;
break;
case 4:
cout<<"亲,把钱转给我把,账号XXXXX!"<<endl;
break;
case 0:
cout<<"谢谢~欢迎下次使用~"<<endl;
break;
default:
cout<<"您输入的功能不存在"<<endl;
break;
}
}