scanf trouble: easy code, inexperienced programer
When ever I use scanf("%d", &n) ; and then have a following printf("Generic Statement:"); My compiler displays the printf statement without me inputting a value for n.
Code:
int x, y;main()
{printf("\nInput an integer value for x:");
scanf("%d", &x);
printf("\nInput an integer value for y:");
scanf(" %d", &y);
if (x==y)
printf("x is equal to y");
if (x>y)
printf("x is greater than y");
if (x<y)
printf("x is less than y");
return 0;
}
This is an example from my book, and it doesn't work.....how frustrating
Such that before I input a value, this is displayed as the output
Code:
Input an integer value for x:
Input an integer value for y:
x is equal to y
Why doesn't the complier wait for the scanf user-input before finishing the code?