In this program I am attempting to determine the winner of rock, paper, scissors. unfortunately when using lowercase letters the code will register it as an invalid entry. How could I get around this?
I thought that converting the characters to upper case would help?
int main()
{
// Declare variables
char playerOne = ' ' ;
char playerTwo = ' ';
char letter= ' ';
// request input
cout << "player 1:Enter r for rock, p for paper or s for scissors: ";
cin >> playerOne;
cout << "player 2:Enter r for rock, p for paper or s for scissors: ";
cin >> playerTwo;
// convert character to uppercase
letter = toupper(letter);
letter = toupper(letter);
letter = toupper(letter);
// Determine game
if (playerOne == 'R')
{
if (playerTwo == 'P')
{
cout << "player 2 has won the game." << endl;
}
if (playerTwo == 'R')
{
cout << "Tie." << endl;
}
if (playerTwo == 'S')
{
cout << "player 1 has won the game." << endl;
}
}
if (playerOne == 'P')
{
if (playerTwo == 'S')
{
cout << "player 2 has won the game." << endl;
}
if (playerTwo == 'P')
{
cout << "Tie." << endl;
}
if (playerTwo == 'R')
{
cout << "player 1 has won the game." << endl;
}
}
if (playerOne == 'S')
{
if (playerTwo == 'R')
{
cout << "player 2 has won the game." << endl;
}
if (playerTwo == 'S')
{
cout << "Tie." << endl;
}
if (playerTwo == 'P')
{
cout << "player 1 has won the game." << endl;
}
}
elseif (playerOne != 'R' && playerOne != 'P' && playerOne != 'S')
{
cout << "Game canceled because of invalid entry." << endl;
}
elseif (playerTwo != 'R' && playerTwo != 'P' && playerTwo != 'S')
{
cout << "Game canceled because of invalid entry." << endl;
}
system("pause");
return 0;
}