Im a newbie programmer on C. And I have an error on my Guess the random number game. Can you please help me fix this? When you got the right answer it shows the "You got the right answer" and shows the "What is the number?"
Here is the code.
Code:
#include<stdio.h>
main()
{
srand(time(0));
int x=rand() % 101,guess=0,tries=3;
printf("The computer will generate a random number, try and guess the random number.\n\n");
printf("*Hint*\n");
printf("It ranges only from 0-100\n");
do{
printf("What is the number?%d",x); //I put the %d,x to know the random number for testing.
scanf("%d",&guess);
if (guess>x){
printf("You'r guess is higher than the number\n");
tries--;
}
else if (guess<x){
printf("You'r guess is lower than the number\n");
tries--;
}
else if (x=guess)
{
printf("\nYou Got the right answer!\n");
printf("The random number is %d",x);
}
}while(tries!=0);
if (tries==0){
printf("\nYou have failed to guess the random number.\n");
printf("The random number is %d",x);
}
getch();
}