Hello again, I'm slowly getting better, I would never have been able to get this far before, but I'm stuck. Here's what my program is supposed to do:
1. Develop a C++ program that uses a while structure 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. Your output screen should somewhat look like the following:
Enter the gallons used (-1 to end): 12.8
Enter the miles driven: 287
The miles/gallon for this tank was 22.421875
Enter the gallons used (-1 to end): 10.3
Enter the miles driven: 200
The miles/gallon for this tank was 19.417475
Enter the gallons used (-1 to end): 5
Enter the miles driven: 120
The miles/gallon for this tank was 24.0000
Enter the gallons used (-1 to end): -1
The overall average miles/gallon was 21.601423
Ok here's what I have so far:
#include <iostream>
using namespace std;
int main()
{
int g=0,m=0,a=0;
while(g>-1)
{
cout<<"Enter the gallons used (-1 to end): "<<endl;
cin>>g;
cout<<"Enter the miles driven: "<<endl;
cin>>m;
a=(m/g);
cout<<"The miles per gallon for this tank of gas was: "<<a<<endl;
}
return 0;
What i'm a bit stuck on:
1.) If a put a decimal in for my gallons used such as: 13.1 the program just starts spitting out information.
2.)If I put in 13 for my gallons used and 200 for my miles driven, my answer should be 15.38461538, but I get just 15. How do I get it to show rounding?
As always, thank you again for all the help.