Im writing a simple little rock paper scissors game and i have ran into a problem.
I'm using a switch statement on the variable decided by cin. It is the variable you set when you type in rock paper or scissors.
So far i am only able to get it to work if i only use a single letter for the case. For example. r for rock. p for paper. s for scissors. I would like to know how to set it so that the cases inside the switch will be "case "rock":". Or something along the likes of it.. a sample of my code.
int main()
{
char c = ' ';
do
{
std::cout << "\na, b, c - e to exit\n";
std::cout << "Input a char: ";
std::cin >> c;
switch( c )
{
case'a':
std::cout << "you entered " << c << '\n';
break;
case'b':
std::cout << "you entered " << c << '\n';
break;
case'c':
std::cout << "you entered " << c << '\n';
break;
case'e':
return 0;
default:
std::cout << "a, b or c were not entered.\n";
}
}while( true );
return 0;
}
If you want to make the user enter the whole word and then do a check, you could do the following:
1 2 3 4 5 6 7 8 9
char handsign[10];
std::cout << "Please enter 'rock', 'paper', 'scissors': ";
std::cin >> handsign;
switch( handsign[ 0 ] ) //check the first letter of the array, 'r', 'p' or 's'
{
....code....
}
i went through and added a score system. Converted it to kbw's suggestion. Works out easier to work with for other things. Finally finished my first proper c++ game. Thanks.