用于atm菜单驱动程序的c++程序


#include <iostream>
#include <conio.h>
using namespace std;
void showmenu()
{
cout << "***menu***" << endl;
cout << " enter 1  to   checkbalance" << endl;
cout << " enter 2  to   deposit" << endl;
cout << " enter 3  to  withdraw" << endl;
cout << ":::::::::::::::::::::::::::::::::::::";
}
int main()
{
int option;
double balance = 500;
double deposit, withdraw;
do {
showmenu();
cout << "option";
cin >> option;
switch (option)
{
case1: cout << "balance is" << balance << endl;
break;
case2: cout << "  enter deposit amount";
cin >> deposit;
balance += deposit;
break;
case3: cout << "withdraw amount";
cin >> withdraw;
if (withdraw <= balance)
{
balance -= withdraw;
}
else
{
cout << "insufficient amount";
break;
}
}
} while (option != 4);
return 0;
getch();
}

当我运行这段代码时,我得到的是这里可用选项的迭代。这似乎是一个简单的代码,但我受够了这些简单的错误,很难纠正。帮助我

我想您忘记在关键字case和case号之间加空格了。我做了一些小改动。更正后的代码:

#include <conio.h>
#include <iostream>
using namespace std; 
void showmenu() {   
cout<<"menu"<<endl; 
cout<<" enter 1 to checkbalance"<<endl; 
cout<<" enter 2 to deposit"<<endl; 
cout<<" enter 3 to withdraw"<<endl; 
cout<<":::::::::::::::::::::::::::::::::::::"<<endl;
} 
int main() {    
int option; 
double balance=500; 
double deposit,withdraw; 
do{ 
showmenu(); 
cout<<"option"; 
cin>>option; 
switch(option) {    
case 1:
cout<<"balance is"<<balance<<endl; 
break; 
case 2:
cout<<" enter deposit amount"; 
cin>>deposit; 
balance+=deposit; 
break; 
case 3:
cout<<"withdraw amount"; 
cin>>withdraw; 
if(withdraw<=balance) {     
balance-=withdraw;
} else {    
cout<<"insufficient amount"; 
}
break;

} 

}while(option!=4);
getch();
return 0; 
}

最新更新