Homework help

Hey guys! This is my first post on this site. So I am taking this c++ intro class which I am really having trouble with. Ive heard that this forum can answer some of my questions. I have this problem on my assignment and I dont know how to start.
Write a program that reads in the number of gallons of gas consumed by your car
and the distance traveled. Your output is the miles per gallon for your vehicle.

If you guys can help at all please do!
Post your code of what you've done so far.
Well...you could start by writing code that asks you to input the number of gallons of gas consumed by your car and how far it's traveled.
Then
                       miles
miles per gallon == -----------
                      gallons
this is what i have so far:
#include <iostream>
using namespace std;

int main()
{
double NumberOfGallons;
double DistanceTraveled;

cout << "Enter Number of Gallons:" >>

That's a bit off. Try changing your last line to:
cout << "Enter Number of Gallons:"; // ; instead of >>

Then to get the input:
cin >> NumberOfGallons;

Do the same for distance and output the result using long double main's formula and you are done.
i think i got it:

#include <iostream>
using namespace std;

int main()
{
double Miles;
double Gallons;

cout << "Enter Miles and Gallons seperated by space: ";
cin >> Miles >> Gallons;
cout << endl;

cout << "MPG= " << Miles / Gallons << endl;

return 0;
}
That looks like it should work. The only problem with doing it that way though is what happens when the user enters milesgallons first?
Last edited on
Topic archived. No new replies allowed.