What is the problem in the code here?
#include <stdio.h>
#include <stdlib.h>
void main() {
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
int a = 5, b = 8;
int inputs;
printf("Guess value of a: \n");
scanf("%d\n", &inputs);
while (inputs > 0){
if(inputs == a){
printf("Correct!\n");
break;
}
else{
printf("Wrong!Try again!\n");
scanf("%d\n", &inputs);
}
}
}
I am just trying the if
stuff but the program takes 2 inputs first (before trying the while
loop or the if
test), and then examines the value of the first input. For example, if I type 1
and then 2
, it checks the 1
first, says it is wrong, and goes on to demand a new input (say 3
) but checks 2
on the next iteration.