Question: #define _ CRT _ SECURE _ NO _ WARNINGS #include #include int main ( ) { const float EXIT _ VAlUE = - 1 .

#define _CRT_SECURE_NO_WARNINGS
#include
#include
int main(){
const float EXIT_VAlUE =-1.0f;
float gallons;
int miles;
float tankful;
printf("Enter the gallon used (%.1f to end)", EXIT_VAlUE);
scanf("%f", &gallons);
while (gallons != EXIT_VAlUE){
if (gallons <=0){
while (gallons != EXIT_VAlUE && gallons <=0){
printf("You entered an invalid value
");
printf("Enter the gallon used (%.1f to end)", EXIT_VAlUE);
scanf("%f", &gallons);
}
}
while (gallons != EXIT_VAlUE){
printf("Enter the miles driven: ");
scanf("%d", &miles);
while (miles <=0){
printf("You entered an invalid value
");
printf("Enter the miles driven: ");
scanf("%d", &miles);
}
tankful = miles / gallons;
printf("The miles/gallons for this tankful was %f", tankful);
}
}
printf("That's all folks, enter any key to exit");
}
The above is my code for this question, but this code has infinity loop and never ends. NOT using continue or break statement, how can I rewrite my code to make it work?
(Gas Mileage) Drivers are concerned with the mileage obtained by their automobiles.
One driver has kept track of several tankfuls of gasoline by recording miles
driven and gallons used for each tankful. Develop a program that uses scanf to input
the miles driven and gallons used for each tankful. The program should calculate and
display the miles per gallon obtained for each tankful. After processing all input information,
the program should calculate and print the combined miles per gallon obtained
for all tankfuls.
This code is in C language.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!