I created a Game in c of rock, paper & scissors. The problem is whenever i choose 1, my com never ever chooses anything other than 0 and 1. You can simply win the game everytime by choosing 1,2,1 or Rock,paper,rock
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int com;
int rng(int com)
{
srand(time(NULL));
return rand() %com;
}
int Uscore = 0;
int Cscore = 0;
int main()
{
int i;
for (i = 1; i <=10; i++)
{
int user;
printf("the computer chose %d\n", rng(2));
printf("enter 0 for rock \nenter 1 paper \nenter 2 for scissors \n");
scanf("%d", &user);
if (com != user)
{
if (com == 0 && user == 1 || com == 1 && user == 2 || com == 2 && user == 0)
{
Uscore++;
}
else
Cscore++;
}
else
printf("its a draw\n");
}
if (Uscore > Cscore)
{
printf("You won");
}
else
printf("you lost");
}
strong text