- π Hi, Iβm @MichalMY
- π Iβm interested in ...
- π± Iβm currently learning ...
- ποΈ Iβm looking to collaborate on ...
- π« How to reach me ...
#include using namespace std; int main() { int input;
cout<<"1. Play game\n";
cout<<"2. Load game\n";
cout<<"3. Play multi-player\n";
cout<<"4. Exit\n";
cout<<"Selection: ";
cin>>input;
cout<<"\n";
switch ( input )
{
case 1: //Note the colon, not a semicolon
cout<<"Play game called";
break;
case 2:
cout<<"Load game called";
break;
case 3:
cout<<"Play Multi-player game called";
break;
case 4:
cout<<"Thanks for playing!\n";
break;
default:
cout<<"Bad input, quitting!\n";
}
return 0;
}
Output :
1. Play gamejjsiw
2. Load game
3. Play multi-player
4. Exit
Selection: 1
Play game called
Important points
The default case is optional. case constant-expression can be int or char (no other datatypes are allowed).