I am trying to make a number guessing game in C in which the computer picks a number and you have to guess which number it is. It states too high if the number you picked is greater than the number to guess and vice versa. However, in my implementation, no matter what number you guess, it is incorrect. I would appreciate if you could tell me what is wrong with the code below.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void){
srand(time(NULL));
char instring[1];
int inint;
int guess;
guess=rand();
while (guess!=inint){
printf("Guess Number\r\n");
gets(instring);
inint=atoi(instring);
if(inint>guess){
puts("too high");
}else if(guess>inint){
puts("too low");
}else{
puts("right");
}
}
return 0;
}