write a C++ program that will calculate the miles per gallon a car gets given the gallons of gas used and the total miles driven. Assume that the car holds 15 gallons of gas and travels a total of 350 miles on a full tank. The formula for miles per gallon (MPG) is given by
MPG = total miles driven/total gallons used.
(so we already know the answer: 23.33 mpg). Your output should be one line:
“The car gets xxx miles per gallon.”, where the xx is the MPG computed by the program (should be about 23.33)
I keep trying and it won't run. this was my latest attempt:
// This program calculates the miles per gallon a car gets given the gallons of gas used and the total miles driven.
double gallons, miles, MPG;
// Get the number of gallons the car holds.
cout << "How many gallons of gas does your car hold? ";
cin >> gallons;
// Get total miles driven.
cout << "How many miles does it travel on a full tank? ";
cin >> miles;
// Calculate the miles per gallon.
MPG = miles / gallons;
// Display the pay.
cout << "The car gets xx miles per gallon" << MPG << endl ;
How many gallons of gas does your car hold? 15
How many miles does it travel on a full tank? 350
The car gets xx miles per gallon23.3333
1>------ Build started: Project: ConsoleApplication8, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\Win32\PlatformToolsets\v141\Toolset.targets(34,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution".
1>Done building project "ConsoleApplication8.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
but first i get this: C:// name of file is not recognized as an internal or external command, oprable program or batch file. press any key to continue....
so i click start without debugging, and it takes me to a black screen and it asks how many gallons of gas....then i put 15, enter and it asks me how many miles does it travel...then i enter 350 and enter, and it takes me to my homescreen