#include<iostream>
usingnamespace std;
int main()
{
srand(time(0));
char playAgain='y';
int a;
cout << "Welcome. You are playing the Classic 'Rock Paper Scissors' Game!" << endl;
cout << "(by Anmol Sethi)" << endl;
cout << "Rules:"<< endl;
cout << "Rock loses to Paper but beats Scissor" << endl;
cout << "Paper beats Rock but loses to Scissor" << endl;
cout << "Scissor beats Paper but loses to Rock" << endl;
while (playAgain !='n')
{
int x=rand()%3+1;
cout << "Choose Rock, Paper or Scissors" << endl;
cout <<"1) Rock" << endl;
cout <<"2) Paper" << endl;
cout <<"3) Scissors"<< endl;
cin >> a;
cout << x<<endl;
if (x == a)
{
cout <<"Tie Game. No one Wins!" << endl;
}
if (x == 1 && a == 2)
{
cout << "Congratulations! You chose Paper and Computer chose Rock. Therefore you WON!" << endl;
}
if (x==2 && a==1)
{
cout << "Sucks! You chose Rock and Computer chose Paper. Therefore you LOST. Haha, LOSER!" << endl;
}
if (x==3 && a==1)
{
cout << "Congratulations! You chose Rock and Computer chose Scissor. Therefore you WON!" << endl;
}
if (x==1 && a==3)
{
cout << "Sucks! You chose Scissors and Computer chose Rock. Therefore you LOST. Haha, LOSER!" << endl;
}
if (x==2 && a==3)
{
cout << "Congratulations! You chose Scissor and Computer chose Paper. Therefore you WON!" << endl;
}
if (x==3 && a==2)
{
cout << "Sucks! You chose Paper and Computer chose Scissors. Therefore you LOST. Haha, LOSER!" << endl;
}
cout << "Would you like to play again? y/n:";
cin >> playAgain;
while (playAgain !='y' && playAgain !='n');
}
cout << "Okay, see you next time!" << endl;
cout << "Thank you for playing a game by Anmol Sethi" << endl;
system ("pause");
}
I made a code for Rock Paper Scissors. The problem is that rand is not really generating a random number from 1-3. If you choose 1 the computer always generates 3. Please help.