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 C++ program that will 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.
Output
Enter the gallons used (-1 to end): 16
Enter the miles driven: 220
The Miles / Gallon for this tank was 13.75
Enter the gallons used (-1 to end): 16.5
Enter the miles driven: 272
The Miles / Gallon for this tank was 16.4848
Enter the gallons used (-1 to end): -1
The overall average Miles/Gallon was 15.1385
- This bottom code is what I had, but I am having trouble inputing the second number of gallons used. The command promt just continously creates more wording and does not allow for an input. What could be the fix or a code that works? Also it would be nice if there was some explanation to each part of the code.
//Header file section
#include<iostream>
using namespace std;
void main()
{
float miles, gallons, MPG, totMiles = 0, totGallons =
0;
int i = 1;
//inputting miles
cout << "Enter mileage for trip:#" << i
<< " :";
cin >> miles;
//inputting gallons
cout << "Enter galllons for trip:#" << i
<< " :";
cin >> gallons;
do
{
MPG = miles / gallons;
totMiles += miles;
totGallons += gallons;
cout << "MPG for trip "
<< i << " :" << MPG << end1;
cout << " MPG for all trips
so far is : "
<<
totalMiles / totGallons << end1;
i++;
//inputting miles
cout << "Enter mileage for
trip:#" << i << " :";
cin >> miles;
if (miles == -1)
break;
//inputting gallons
cout << "Enter gallons for
trip:#" << i << " :";
cin >> gallons;
} while (miles != -1);
cout << "Thanks for using our MPG program!"
<< end1;
}//end main
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of...
Drivers are concerned with the mileage their automobiles get. One driver has kept track of several tankfuls of gasoline by recording the miles driven and gallons used for each tankful. Develop a C# app that will input the miles driven and gallons used (both as integers) for each tankful. The app should calculate and display the miles per gallon obtained for each tankful and display the combined miles per gallon obtained for all tankfuls up to this point. All averaging...
Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tanks of gasoline by recording miles driven and gallons used for each tank. Develop a program using a while loop that will input the miles driven and the gallons used for each tank. The program should calculate and display the miles per gallon obtained for each tank. After processing all input information, the program should calculate and print the overall miles per gallon...
7.11 Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording the number of miles driven and the number of gallons used for each tankful. Develop a script that will take as input the miles driven and gallons used (both as integers) for each tankful. The script should calculate and output HTML5 text that displays the number of miles per gallon obtained for each tankful and the combined...
Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankful of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that inputs the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful and print the combined miles per gallon obtained for all tankfuls up to this point.
Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...
I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked,...
create an application in VISUAL BASIC that calculates a cars gas mileage. The formula for calculating the miles that a car can travel per gallon of gas is MPG = Miles/Gallon In the formula MPG is miles-per-gallon, miles is the number of miles that can be driven on a full tank of gas, and gallons is the number of gallons that the tank holds. The applications form should have TextBox controls that let the user enter the number of gallons...
// Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter your class section, and time /* The program TripCost.cpp uses pointers to calculate the cost of a trip depending on the cost of a gallon of gas, the number of miles, and the number of miles per gallon a car gets. */ /* The cost of gas, the number of miles, and number of miles per gallon is entered. */...
Hi, Hi, I need someone to write a program in Phython 3.6, and please I will appreciate if the code is error free and indented correctly. The output would be preferable. thanks Write a GUI program that translates the Latin words to English. The window should have three buttons, one for each Latin word. When the user clicks a button, the program displays the English translation in a label. 3. Miles Per Gallon Calculator Write a GUI program that calculates...
The Python program will compute total mileage for all trips included : Trip: 1,2,3,4 Mileage: 200, 400, 800, 10 Gas: 10, 17, 39, 1 As well as the fuel efficiency in miles per gallon. Your program will open the file, read it line by line and add the miles driven and the gallons gas consumed then calculate the average fuel efficiency. It will then write Once the program has read all the lines, it will write the total miles driven,...