Calculating MPG using simple C++

Jul 17, 2016 at 8:00pm
I have to create a program calculating a car's gas mileage. The program should ask the user to enter the number of gallons of gas the car can hold, and the number of miles it can be driven on a full tank. It should then display the number of miles that may be driven per gallon of gas.

This is what I have so far. It seems okay but I could be completely wrong, this is my fist ever in a class creating programs so I am completely new to this.

#include <iostream>
using namespace std;
int main()
{
double capacity, miles, average
cout << "enter he number of gallons a tank can hold ";
cin >> capacity;
cout << "enter the number of miles driven on a full tank ";
cin >> miles;
average = miles/capacity
// calculate the dividend of the two numbers
// display the MPG
cout << the car’s mpg is: " << average << endl;
system("PAUSE");
return 0;

PLEASE HELLLP! :)
Jul 17, 2016 at 8:05pm
Hi,
Firstly :
double capacity, miles, average
Missing a semi-colon ( ; ) at the end of the statement.

==>
double capacity, miles, average;
Jul 17, 2016 at 8:07pm
Secondly :
average = miles/capacity
Missing a semi-colon ( ; ) at the end of the statement.

==>
average = miles / capacity;
Jul 17, 2016 at 8:10pm
Thirdly :
cout << the car’s mpg is: " << average << endl;
Missing a quotation mark (") at the beginning of the string.

==>
cout << "the car’s mpg is: " << average << endl;
Jul 17, 2016 at 8:11pm
Okay thank you!
Should I have put // display the mpg after cout << the car's mpg is: "? @5a8Ym39o6
Last edited on Jul 17, 2016 at 8:11pm
Jul 17, 2016 at 8:17pm
> Should I have put "// display the mpg" after cout << "the car's mpg is: "?
You can put this comment everywhere, but do not let its green color cover this line cout << "the car's mpg is: ";
Jul 17, 2016 at 8:20pm
Okay sweet.
Jul 17, 2016 at 8:29pm
Good to hear :)
Jul 17, 2016 at 8:32pm
Thank so much for your help :)
Topic archived. No new replies allowed.