Everytime I type a character, the number 1 appears in the next line. And i just keep getting the message "Wrong! I have more than that." even when I type a number bigger than 1023
Do you know what's wrong. I've spent hours on this.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
srand(time(NULL));
int candies = rand() % 1024;
int c;
printf("Guess how many candies I have. I have less than 1024.\nGo on! Type a number!\n");
while(1)
{
c = scanf("%d", &c);
if(c == candies)
{
printf("%d\n", c);
printf("That's correct! How did you know that?");
return 0;
}
else if(c > candies)
{
printf("%d\n", c);
printf("No. I wish I had that much...\n");
}
else if(c < candies)
{
printf("%d\n", c);
printf("Wrong! I have more than that!\n");
}
}
}