Код работает нормально. Я просто пропускаю элемент, где, если конечный запрос на повторение игры, если я введу «a» как пользователя, я бы хотел, чтобы код повторил вопрос с новым оператором cout, таким как «неверный ответ, пожалуйста». ответьте да / нет и если да, то, очевидно, игра перезапускается сама
(Рок бумага ножницы игра ч / б 2 игрока)
int main(int argc, const char * argv[]) {
char playAgain ='y' ; // loop control
do
{
char Player1;
char Player2 = '\0';
cout << "Player 1, Enter R, P, or S: "; // Player 1
cin >> Player1;
Player1 = toupper(Player1);
while (Player1 != 'R' && Player1 != 'P' && Player1 !='S' )
{
cout << "please only answer R , P , or S: " << endl;
cin >> Player1;
Player1 = toupper(Player1);
}
{
cout << "Player 2, Enter R, P, or S: "; // Player 2
cin >> Player2;
Player2 = toupper(Player2);
while (Player2 != 'R' && Player2 != 'P' && Player2 !='S' )
{
cout << "please only answer R , P , or S: " << endl;
cin >> Player2;
Player2 = toupper(Player2);
}}
if (Player1 == Player2) //TIE
{
cout << "Nobody wins."<<endl;}
else if (Player1 == 'R' && Player2 == 'P')
{
cout << "Paper covers rock, Player 2 wins."<< endl;
}
else if (Player1 == 'P' && Player2 == 'R')
{
cout << "Paper covers rock, Player 1 wins."<< endl;
}
else if (Player1 == 'S' && Player2 == 'P')
{
cout << "Scissors cut paper, Player 1 wins."<< endl;
}
else if (Player1 == 'P' && Player2 == 'S')
{
cout << "Scissors cut paper, Player 2 wins."<< endl;
}
else if (Player1 == 'R' && Player2 == 'S')
{
cout << "Rock breaks scissors, Player 1 wins."<< endl;
}
else if (Player1 == 'S' && Player2 == 'R')
{
cout << "Rock breaks scissors, Player 2 wins."<< endl;
}
{ cout << "Play again? (y/n): "; // Player 1
cin >> playAgain;
if (playAgain=='N' || playAgain=='n')
{ cout <<"BYEEEEE"<<endl;}
}}
while (playAgain=='Y' || playAgain=='y');
return 0;
}