need help with a program

i am currently in a c++ class and i am new to all this
for some reason i do not get this math for the program.....please help
i have to create a program that will determine the cost of a vacation by car to a variety of locations
distance
price per gallon
miles per gallon

i got this so far

#include <iostream>
#include<iomanip>

using namespace std;

int main()
{
float distance=0.0;
float costpergallon=0.0;
float milespergallon=0.0;

cout<<" enter trip distance ";
cin>>distance;
cout<<" enter cost per gallon of gas ";
cin>>costpergallon;
cout<<" enter miles per gallon of gas ";
cin>>milespergallon;

cost=(distance / milespergallon)*pricepergallon;

cout<<" trip distance "<<setprecision(2)<<tripdistance<<'\n'
<<" cost per gallon "<<setprecision(2)<<costpergallon<<'\n'
<<" miles per gallon "<<setprecision(2)<<milespergallon<<'\n'
<<" cost to use this vehicle for trip "<<setprecision(2)<<costtousethisvehiclefortrip<<endl;

cin.get()
return 0;
}


can someone tell me what i did wrong
Last edited on
This is grade school math.
How many miles do you have to travel?
How many gallons of gas will that take if you know the miles per gallon of the car?
How much will the gas cost if you know the cost per gallon?

i figured out the math dont know how to type it
another words not sure how to finish this program so program works
i know the math is distance / miles per gallon *price per gallon
Last edited on
1) You need a variable to contain the result of your calculation, then display that result.
2) You need to wrap your statements into a main function:

1
2
3
4
int main ()
{  // place code here
    return 0;
}


Topic archived. No new replies allowed.