Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that will compute the mpg of a car. 1. The user must enter the

ID: 3539155 • Letter: C

Question

Create a program that will compute the mpg of a car.
1. The user must enter the number of gallons.
2. The user must enter the distance traveled.
3. The program will computer mpg and output mgp to the user.
4. You must use a template for your mpg function.
You must also include a screen shot of the program running. Create a program that will compute the mpg of a car.
1. The user must enter the number of gallons.
2. The user must enter the distance traveled.
3. The program will computer mpg and output mgp to the user.
4. You must use a template for your mpg function.
You must also include a screen shot of the program running.

Explanation / Answer

write a C program that will calculate the MPG for a car . Ask the user to input the number of miles driven and the amount of gas used . Display the MPG for the trip. Create a loop that allows the user to repeat until a-1 is entered in the miles driven prompt. At that time calculate and display the average MPG for the car.

example

enter miles driven:250
enter gallons of gas used:11.2
average MPG is 22.32

enter miles driven : 300
enter gallons of gas used:12.4
Average MPG is:24.19

enter miles driveb :-1

Average MPG for your car is:23.30



========================================

ANS:



#include <stdio.h>


int main(){
float milesDriven;
float gallonsUsed;
int rounds = 0;
float allMilage = 0;
while(milesDriven != -1 || gallonsUsed != -1){
printf("Enter miles driven:");
scanf("%f",&milesDriven);
if(milesDriven == -1)
break;
printf("Enter gallons used:");
scanf("%f",&gallonsUsed);
printf("Average MPG is: %f",(milesDriven/gallonsUsed));

printf(" ... ");

allMilage += (milesDriven/gallonsUsed);
rounds++;

}
printf("Average MPG for your car is: %f ",(allMilage/rounds));
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote