Switch statement are much easier to read than multiple if statements, BUT unfortunately you need case statements that evaluate to integers. You could do this:
Code:
char choice;
cout<<"Would you like to add (A) or subtract (S)?"<<endl;
cin>>choice;
switch (choice)
{
case 'A':
//add
break;
case 'S':
//subtract
break;
default:
cout<<"Your choice was invalid."<<endl;
}
but unfortunately you cannot do this:
Code:
string choice;
cout<<"Would you like to add or subtract?"<<endl;
cin>>choice;
switch (choice)
{
case "add":
//add
break;
case "subtract":
//subtract
break;
default:
cout<<"Your choice was invalid."<<endl;
}
I'm not sure if there is an easy way around this with strings, I can't think of anything off the top of my head.