Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

I need help with my C++ class ( we are using Microsoft Visual Studio 2008)?

I need more importantly the code because I already have an idea of the pseudocode.

Write a program that will calculate the average miles per gallon for a

salesperson. The salesperson leaves his home every Monday and returns every Friday. He travels by company car. Each day on the road, the salesperson records the amount of gasoline put in the car. Given the starting odometer reading (that is, the odometer reading before he leaves on Monday) and the ending odometer reading (the odometer reading after he returns home on Friday), the program will find the average miles per gallon. The output of the program should include 1. starting odometer reading, 2. ending odometer reading, 3. total mileages, 4. Gasoline purchased on Monday, 5. Gasoline purchased on Tuesday, 6. Gasoline purchased on Wednesday, 7. Gasoline purchased on Thursday, 8. Gasoline purchased on Friday, 9. Total Gasoline purchased, and 10. average miles per gallon. All output data should be aligned by the decimal points

4 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    long odoMonday;

    long odoFriday;

    double gallonsMonday;

    double gallonsTuesday;

    double gallonsWednesday;

    double gallonsThursday;

    double gallonsFriday;

    // Ask for the starting odometer reading.

    // Save the starting odometer reading into odoMonday

    // Ask for the ending odometer reading.

    // Save the ending odometer reading into odoFriday

    // Ask for and save the gallons purchased for each day.

    double total = // add all of the variables holding the gallons pre day.

    double average = total / 5.0;

    double mpg = (odoFriday - odoMonday) / total;

    // Ouput all of these.

    Good luck with it.

  • Anonymous
    5 years ago

    C++ is a superset of of C. You should be able to write C inside a C++ application. As an aside, you might want to find a nicer environment to learn in, as I'd been writing C++ professionally for 8 years before using Visual Studio and MFC. Its a nightmare and a perfect illustration of why Microsoft products are full of bugs and security flaws.

  • 1 decade ago

    Just start with something, then build. Start by implementing one day. Once you get that working add the other days. Once thats good add a starting odometer reading.

    Steps are key to good programming. On a small scale program like this you may be able to do it all at once, but what happens when you need to write a program with 10, 000 lines of code?

  • Anonymous
    1 decade ago

    If you have the pseudocode what's the problem?

Still have questions? Get your answers by asking now.