Rand problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<iostream>
using namespace 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.
nvm I fixed it.
Topic archived. No new replies allowed.