Need help on this while statement, thanks!
I'm wondering if something is wrong with this code.
the supposed output should be:
Code:
Enter gallons consumed(-1 to end): -1
//skips the miles prompt and ends the loop
...some code after loop...
but it still asks for the miles value to be entered and then ends the loop. what's wrong with this? please help.
here's the code:
Code:
while (gallon != -1)
{
printf("Enter gallons consumed(-1 to end): ");
scanf("%f", &gallon);
printf("Enter miles: ");
scanf("%f", &miles);
tmil += miles;
tgal += gallon;
mpg = miles/gallon;
printf("Your fuel efficiency is %.2f\n\n", mpg);
}
Thanks,
Jann