int main()
{
int userInput, gesture;
cout << "Rock(0), Paper(1), Scissor(2): ";
cin >> userInput;
srand(time(0));
gesture = rand() % 3;
if (isdigit(userInput) && userInput >= 0 || userInput <= 2) //I think it's a logic error, but idk how to fix it.
{
switch (gesture)
{
case (0):
if (userInput == gesture)
cout << "The computer is rock. You are rock too. It is a draw." << endl;
else if (userInput == 1 && gesture == 0)
cout << "The computer is rock. You are paper. You win." << endl;
else if (userInput == 2 && gesture == 0)
cout << "The computer is rock. You are scissor. You lose." << endl;
break;
}
}
else
/* when the input is >2 or <0 it display the below statement, butwhen the input is an alphabet or a word, it doesn't reach here cout<<"Invalid input.";
return 0;
}
Aucun commentaire:
Enregistrer un commentaire