Hi,
In working through t the Switch Case example in the C++ tutorial I wanted to try and have the list use characters (a,b,c,d) rather than numbers (1,2,3,4) as the the case identifiers.
Here is the code (in case you forgot:-)
Code:
#include <iostream>
using namespace std;
void playgame()
{
cout << "Play game called";
}
void loadgame()
{
cout << "Load game called";
}
void playmultiplayer()
{
cout << "Play multiplayer game called";
}
int main()
{
int input;
cout<<"1. Play game\n";
cout<<"2. Load game\n";
cout<<"3. Play multiplayer\n";
cout<<"4. Exit\n";
cout<<"Selection: ";
cin>> input;
switch ( input ) {
case 1: // Note the colon, not a semicolon
playgame();
break;
case 2: // Note the colon, not a semicolon
loadgame();
break;
case 3: // Note the colon, not a semicolon
playmultiplayer();
break;
case 4: // Note the colon, not a semicolon
cout<<"Thank you for playing!\n";
break;
default: // Note the colon, not a semicolon
cout<<"Error, bad input, quitting\n";
break;
}
cin.get();
}
I tried changing "input" from int to char with no joy. I also tried just changing the numbers to letters in case with the same predictable results. Is there a library I need to declare or am I on a fools errand?
TIA