Of course it asks you for it again. Follow the flow of your loop:
Code:
while (gallons != -1){ /* start this loop cycle if gallons isn't -1 */
printf("Enter the gallons used (-1 to end): "); /* ask for gallons */
scanf("%d" , &gallons); /* read gallons */
printf("Enter the miles driven: "); /* ask for miles, regardless of
what gallons is, because you
have no check here */
scanf("%d" , &miles); /* read miles */
mileage = gallons / miles; /* coversion */
total = total + mileage; /* more stuff */
counter = counter + 1; /* more stuff again */
printf("The tank's mileage was %d:\n " , mileage); /* display stuff */
/* jump to top of the loop */
}
/* only check this once you've finally gotten outside of the loop */
if(gallons = -1){
average = total / counter;
printf("The overall mileage was %d: " , average);
}
return 0;
}
It does exactly what you told it to do.
Quzah.