Your program appears to be correct. Evidence:
http://coliru.stacked-crooked.com/a/cbbb62a392a21186
Why isn't the prompt showing up, you might ask?
This is because standard output is buffered.
Before characters you put into
printf()
show up on standard output, they get shoved into a block of memory somewhere, which is written to standard output when (among other things):
- a newline is reached
- you tell the computer to flush the buffer.
The rules are slightly different in C++ (your program is C -- hopefully you know this), and the behavior may vary cross-system.
After each invocation of
printf()
that doesn't end with a newline, call
fflush(stdout);
. This will flush the internal buffer into standard output:
1 2 3 4 5 6 7 8
|
printf("\n Enter the value of a:"); fflush(stdout);
scanf("%d", &a);
printf("\n Enter the value of b:"); fflush(stdout);
scanf("%d", &b);
printf("\n Enter the value of x:"); fflush(stdout);
scanf("%d", &x);
printf("\n Enter the value of y:"); fflush(stdout);
scanf("%d", &y);
|
There are two minor issues with your code:
int a,b,x,y=0;
Declares four integers but only initializes
y
. In order to initialize all four variables you need to either duplicate the initializer:
int a = 0, b = 0, x = 0, y = 0;
Or do something like this:
int a,b,x,y; a=b=x=y=0;
In this context it is NOT acceptable to leave the variables uninitialized, because
printf()
can potentially fail to assign a value to each of those variables, which would cause your program to use an uninitialized value. (But maybe you don't care about errors now; if that's the case, just ignore me.)
Also,
int f=(a-b)*(x-y);
Should never be modified by your program after its' value is initialized. Mark it
const
. Doing this consistently will help prevent subtle bugs in the long run:
int const f=(a - b)*(x - y);
---
The buffering allows the computer to make just one big write instead of many tiny ones, which can potentially speed things up significantly.