Hello All,
I am new to this so I am not sure if this is going to post correctly. I am trying to create a rock, paper, scissors game. My issue with my code is I only want the code to repeat if the computer picks the same choice as the user, however, my code is repeating everytime. If anyone could help me with this I would appreciate it!
Thanks,
Taylor
//This program let a user play rock, paper, scissors with a computer.
#include <iostream>
#include <cstdlib> //For rand and srand
#include <ctime> //For the time function
using namespace std;
int main()
{
//Get a random number.
unsigned seed= time(0);
//Seed the random number generator
srand(seed);
int userChoice;
int computerChoice = rand()%3+1;
cout << "Rock, Paper, Scissors Game\n";
cout << "You are playing against the computer\n";
cout << "Type 1 for rock\n";
cout << "Type 2 for paper\n";
cout << "Type 3 for scissors\n";
cin >> userChoice; //User enters choice here
cout <<computerChoice<<endl;
if (userChoice == 1)
{
if (computerChoice == 1)
cout << "We have made the same choice. Rematch!\n\n\n\n";
else if (computerChoice == 2)
cout << "Paper wraps rock, computer wins\n";
else if (computerChoice == 3)
cout << "Rock smashes scissors, you win\n";
}
if (userChoice == 2)
{
if (computerChoice == 2)
cout << "We have made the same choice. Rematch!\n\n\n\n";
else if (computerChoice ==1)
cout << "Paper wraps rock, you win\n";
else if (computerChoice == 3)
cout << "Scissors cut paper, computer wins\n";
}
if (userChoice == 3)
{
if (computerChoice == 3)
cout << "We have made the same choice. Rematch!\n\n\n\n";
else if (computerChoice == 2)
cout << "Scissors cut paper, you win\n";
else if (computerChoice == 1)
cout << "Rock smashes scissors, computer wins\n";
}
return main();
}