I am writing this program about Gas mileage, In the program I am assigning a value that is -1 as a sentinel value, that's why I use the While loop. The problem is I can input gallon variable, but the miles variable keep repeating over and over again.
My question is how can I have the mile variable repeated only one time in the loop? So that I can solve it.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int gallon;
int miles;
int total;
total = 0;
printf( "Enter gallon used (-1 to end): " );
scanf( "%d", &gallon);
while( gallon != -1 ) {
total = miles / gallon;
printf( "Enter miles driven" );
scanf("%d", &miles);
}
return 0;
}