Need some assistance with C++ homework, we are making a gas mileage calculator

Hey guys. I just started C++ last week in college and we already got slammed with the first homework assignment. Here is the assignment:

"Write a program that will ask the user to input:
The number of gallons in the tank
The fuel efficiency in miles per gallon
The price of gas per gallon
Then it will print out how far the car can go with the gas in the tank and print the cost per 100 miles."

well I have been killing myself trying to figure it out. All we've done in class so far is the "Hello World" program, and now this homework. So I have read my chapters over and over. This is all I can come up with so far, and of course, it isn't working. Using VS2008 to compile btw(dont know if it matters):

#include <iostream>

{

int main()


int odometer1;

int odometer2;

int gallons;

int mph;


std::cin<<"Enter the first odometer reading... "<<std::endl;

odometer1 = Convert.ToInt32<<std::>>cin;

std::cin<<"Enter the second odometer reading.. "<<std::endl;

odometer2 = Convert.ToInt32(Console.ReadLine());

std::cin<<"Enter gallons used................. ")<<std::endl;

gallons = Convert.ToInt32(Console.ReadLine());


mph = (odometer2 - odometer1) / gallons;


public:
static void WriteLine()
"odometer1 = {0}", odometer1;

public:
static void WriteLine()
"odometer2 = {0}", odometer2);

public:
static void WriteLine()
"gallons = {0}", gallons);

public:
static void WriteLine()
"Gas mileage is {0} miles/gal",mph);

public: static String* ReadLine();
}



well there it is.. Its all wrong. I dont even know if im close. I just need some assistance. If anyone can help me out, and point me to the right direction, i'd really appreciate it. Thanks in advance
You should use cout for output, not cin std::cout<<"Enter the first odometer reading... "<<std::endl;

The way you are getting input is wrong, here is the right sintax:
std::cin >> odometer1;

1
2
3
public:
static void WriteLine()
"odometer1 = {0}", odometer1;
Doesn't make sense, the right thing is like this:
std::cout << "odometer1 = {0} " << odometer1;

What is public: static String* ReadLine(); supposed to do?

I dont know. Im an idiot. I think I just read too much and didn't do enough thinking. I dont even think I should take programming. I been fixing computers for 8 years and I just figure I should take the next leap.. But I dont know what public: static String* Readline(); does..
Well, actually it isn't legal that line in a function body, that looks as a declaration for a class method. My question is: What do you want to do at that point?

BTW, I've noticed another error, the 1st brace should be after int main()


If you want some easy C++ tutorials try here: http://www.cplusplus.com/doc/tutorial/
Last edited on
Topic archived. No new replies allowed.