This a program i write for practice. The problem I'm facing is inside the while statement. Is it okay to divide, in this case, the miles(which is inside the the while) with gall(outside the while). I tried to compile it and the answer given was 0.00000
P/S. This program is not complete.
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
double miles,
gall,
x;
printf("Enter the gallons used (-1 to end)> ");
scanf("%lf", &gall);
while (gall!=-1){
printf("Enter the miles driven> ");
scanf("%d", &miles);
x = miles/gall;
printf("The miles/gallon for this tank was %f.\n", x);
}
if (gall== -1){
printf("Invalid\n");
} else {
printf("The overall average miles/gallon was ");
}
system("PAUSE");
return 0;
}