cout << "Hello player, Please between Rock (1), Paper (2), and Scissors (3) to play the game." << endl
<< endl;
cout << "Alternatively, you can press 4 to escape the game." << endl << endl;
cin >> userChoice;
srand(time(0));
compChoice = ((rand() % 3) + 1);
while (userChoice <= 0 || userChoice >= 5){
cout << "Error. Wrong input." << endl << endl;
//check works fine.
cin >> userChoice;
}
if (userChoice == 1){
cout << endl << "You have picked rock." << endl;
if (compChoice == 2){
cout << "The AI has picked paper and you lose!" << endl;
}
else if (compChoice == 3){
cout << "The AI has picked Scissors and you WIN!" << endl;
}
else {
cout << "You have tied with your opponent!" << endl;
}
//Will be showed no matter the choice above.
cout << "You can play again by pressing 1, 2, or 3 for rock, paper, or scissors respecively. Or 4 to leave the game."
<< endl << endl;
}
if (userChoice == 2){
cout << "You have picked paper." << endl;
if (compChoice == 1){
cout << "The AI has picked rock and you WIN!" << endl << endl;
}
else if (compChoice == 3){
cout << "The AI has picked scissors and you lose!" << endl << endl;
}
else {
cout << "You have tied with your opponent!" << endl << endl;
}
}
if (userChoice == 3){
cout << "You have picked scissors." << endl << endl;
if (compChoice == 1){
cout << "The AI has picked rock and you lose!" << endl << endl;
}
else if (compChoice == 2){
cout << "The AI has picked paper and you WIN!" << endl << endl;
}
else {
cout << "You have tied with your opponent!" << endl << endl;
}
}
cout << "If you would like to play again pick 1-3 for rock, paper, or scissors." << endl;
cout << "Or now that you've played you can press 4 to escape." << endl;
cin >> userChoice; //Breaks out of the loop.
compChoice = ((rand() % 3) + 1); //Second PC choice so it's not the same.
} //Final loop
//This is for the loop
system("Pause");
return 0;
}
Finally got it working to how my teacher wanted (I think her instructions can be vauge.)