Creating Rock Paper Scissors game.

closed account (1R91hbRD)
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879`` ``````/****************************************************************************************** **When the program begins, a random number in the range of 1 through 3 is generated. **If the number is 1, then the computer has chosen rock. **If the number is 2, then the computer has chosen paper. **If the number is 3, then the computer has chosen scissors. **Then the user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. *******************************************************************************************/ #include #include #include using namespace std; int main() { system("color D5"); srand(time(NULL)); //seeds the generator int rand_num; rand_num = rand()%3+1; int choice; cout << "* * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl << "Welcome to Megatron's Rock, Paper, Scissors game." << endl << "* * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl <> play; while (play == 'y' || play == 'Y' ) { cout << "Can you beat Megratron?" << endl << "(Type 0 for Rock, 1 for Paper or 2 for Scissors)" << endl << endl; cin >> choice; // get choice from the user //compare choice to the rand //display results //play again while (choice == 1) { if (rand_num == 2) cout << "Paper beats rock! Sorry, you lose!\n\n\n\n"; else if (rand_num == 3) cout << "Rock beats scissors! You win!\n\n\n\n"; else if (rand_num == 1) cout << "It's a tie!\n\n\n\n"; } if (choice == 2) { if (rand_num == 2) cout << "Paper beats rock! You win!\n\n\n\n"; else if (rand_num == 3) cout << "Scissors beat paper! Megatron wins!\n\n\n\n"; else if (rand_num == 1) cout << "It's a tie!\n\n\n\n"; } if (choice == 3) { if (rand_num == 2) cout << "Scissors beat paper! You win!\n\n\n\n"; else if (rand_num == 3) cout << "Rock beats scissors! Sorry, you lose!\n\n\n\n"; else if (rand_num == 1) cout << "It's a tie!\n\n\n\n"; } else cout << "invalid input, please try again" <
Also, is this `while (choice == 1)` meant to be` if (choice == 1) `?