I have written this program to play rock, paper and scissors with the computer. The following generator() is used to generate the computers choice out of rock paper and scissors:
// Function to generate computer's choice
char generator()
{
int key= rand();
int gen = (key % 3)+1;
char pc;
// written this print to check what no. random is generating.
printf("The random function using rand is : %d",key);
switch (gen)
{
case 1:
pc = 'r';
break;
case 2:
pc = 'p';
break;
case 3:
pc = 's';
break;
}
return pc;
}
Ideally the rand() function should generate a random no. every time. And if I find it's modulus with 3 it should give three possible choices of remainders 0,1,&2. Then I would have assigned a value out of rock, paper and scissors to one out of each value. Then this would be the computer's choice and this would be then matched again the input of the player( Who again enter one choice out of rock, paper and scissors ) and the winner is decided by the usual rules of the game. But the rand() is always generating the number 41. And hence the game is not working properly Can anybody please explain why?