I am trying to start my c++ final and am running into a bit of trouble already. I have tried to get just the cout statement for each case to display but am not having any luck. Any feedback is welcomed.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
void displayMenu();
/*class account{
public:
int act_num,
withdrawls,
deposits;
string name;
double rate,
fee;
}*/
void displayMenu()
{
cout<<"Please input which selection you would like"<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"1. Savings Account Deposit "<<endl;
cout<<"2. Checking Account Deposit "<<endl;
cout<<"3. Savings Account Withdrawl "<<endl;
cout<<"4. Checking Account Withdrawl "<<endl;
cout<<"5. Update and Display Account Statistics "<<endl;
cout<<"6. Exit "<<endl;
}
int main()
{
int choice;
do
{
displayMenu();
switch(choice)
{
case 1: cout<<"Your savings account has a balance of $"<<endl;
//cout<<savings.getbalance<<endl;
//cout<<"How much would you like to deposit?"<<endl;
//cin>>savings.deposit<<endl;
break;
case 2: cout<<"Your checking account has a balance of $"<<endl;
//cout<<checking.getbalance<<endl;
//cout<<"How much would you like to deposit?"<<endl;
//cin>>checking.deposit<<endl;
break;
case 3: cout<<"Your savings account has a balance of $"<<endl;
//cout<<savings.getbalance<<endl;
//cout<<"How much would you like to withdraw?"<<endl;
//cin>>savings.withdraw>>endl;
break;
case 4: cout<<"Your checking account has a balance of $"<<endl;
//cout<<savings.getbalance<<endl;
//cout<<"How much would you like to withdraw?"<<endl;
//cin>>checking.withdraw>>endl;
break;
case 5: cout<<"Your checking account currently has $"<<endl;
//cout<<getBalance.checking<<endl;
//cout<<"Your savings account currently has $"<<endl;
//cout<<getBalance.savings<<endl;
break;
}
cin>>choice>>endl;
}
while(choice <= 5);
return 0;
}
my error:
1>i:\computer science 2\practice\structures_again\structures_again\source1.cpp(74): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion)
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1053): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1060): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1067): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,unsigned char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1>
moving the cin line (line75) to line 46 did not change anything.
however, initializing choice to 0 was what fixed it. I dont really like that i have to initialize the variable to 0. seems like "pass by value" is being applied when choice changes from 0 (the initial value) to, lets say, menu choice 2.
I hope that makes sense. If it doesn't, i thank you for your help