Actually, I don't think you have it correct, unless you have a newer version of the program that you didn't show. Your input is
Code:
54752 2.64
53247 2.87
52247 2.20
57412 2.78
59321 2.58
49665 2.86
52001 2.55
Your output is
Code:
dprev = 54752, pprev = 2.640000
d = 52247,p = 2.200000
The efficiency is -0.287000
d = 59321,p = 2.580000
The efficiency is 0.145626
d = 52001,p = 2.550000
The efficiency is 0.122432
You have 7 lines of input, you should see 6 iterations of the loop (you the first line before the loop, then read the next 6 lines in the looip).
As Matticus and I pointed out, you need to read into d and p once per loop iteration. Maybe I wasn't clear enough, but you only need the scanf in the loop condition itself. Like so:
Code:
while (scanf == 2)
maybe print values
calculate efficiency
update dprev and pprev
Correct output should look like this (I added a line to print dprev and pprev inside the loop, just to check):
Code:
dprev = 54752, pprev = 2.640000
d = 53247,p = 2.870000
dprev = 54752, pprev = 2.640000
The efficiency is -0.175415
d = 52247,p = 2.200000
dprev = 53247, pprev = 2.870000
The efficiency is -0.287000
d = 57412,p = 2.780000
dprev = 52247, pprev = 2.200000
The efficiency is 0.042594
d = 59321,p = 2.580000
dprev = 57412, pprev = 2.780000
The efficiency is 0.145626
d = 49665,p = 2.860000
dprev = 59321, pprev = 2.580000
The efficiency is -0.026719
d = 52001,p = 2.550000
dprev = 49665, pprev = 2.860000
The efficiency is 0.122432
Also, I told you to check the first scanf, the one above the loop, to make sure it read properly. If it didn't, you could get stuck in an infinite loop or encounter other problems.
And, you're not checking d-dprev to ensure it's non-zero before you try to divide -- this can be very bad, it can crash your program.