How do you use a variable type char in a switch statement?
Below is a segment of code that I'm working on. Can anybody tell me how to fix it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void getMoreFunds(int &balance)
{
char answer;
cout<<"Would you like to replenish your funds? (y/n)";
cin>>answer;
switch (answer){
case "y":
balance += 50;
cout<<"Your balance is now "<<balance<<"."<<endl;
break;
case "n":
break;
default:
cout<<"Invalid response"<<endl;
}
}
|
Also, I'm not sure if that is the correct usage of a reference parameter... Could somebody tell me if I'm on the right track there as well?
Thanks in advance to anybody who can help me!
Last edited on
Use single quotes for character literals
Thanks! I appreciate your help.