I have to write a program where a user trys to pick a number. The code i've written below always exits after 2 guesses abd says the guess was correct even if it's wrong. Can anyone see what i'm doing wrong? Thanks
# include <stdio.h>
# define NUMBER 50
int main(void)
{
int guess=0, count=0, loop=0;
printf("Guess> ");
scanf("%d", &guess);
while (loop==0)
{
if (guess < NUMBER)
{
count++;
printf("Too small - guess again> ");
scanf("%d", &guess);
}
if (guess > NUMBER)
{
count++;
printf("Too big - guess again> ");
scanf("%d", &guess);
}
if (guess==NUMBER)
{
loop=1;
count++;
printf("Correct. That took you %d guesses.\n", count);
}
return 0;
}
}