954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

HOW TO PROGRAM C++ homework

I think I know how to initialize the program, but i am doing a self learner and i am not sure how to begin or what to initialize. If anyone has any ideas please help me out.

Here is a problem if you dont have the book... C++ HOW TO PROGRAM

Drivers are concerned with the milage obtained by their automobiles. One driver has kept track of serveral tankfuls of gasolines by recording miles driven and gallons used each tankful. Develop a C++ program tha uses a WHILE structure to input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.

Thanks for helping

NitrousGT
Newbie Poster
1 post since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

Pretty straight forward.

You will need a set of variables to store the accumulating Miles, and Gallons. As well as an array to store a specific drivers set of miles per gallons. The while loop will allow you to fill and read ("empty") the array to display the results.

Not sure if that was the kind of help you were asking for, let me know if I can be of more help.

:cool:

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

I also need help getting started on this same program. But I don't even know where to start...
any help would be great!

sjopkg
Newbie Poster
4 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 
I also need help getting started on this same program. But I don't even know where to start... any help would be great!
// your code here
 
 int main()
 {
    // your code here
    return 0;
 }
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 
// your code here
 
 int main()
 {
    // your code here
    return 0;
 }


How would you begine writing the code...is there a certain format or steps to take in order to compile the program?

sjopkg
Newbie Poster
4 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

I have to do this same program..
this is what I have so far.
but i don't know how to calculate the average miles per gallon or the combined miles per gallon. where and how do I add this into the program. How can i add a sentinel value to determine when u are finished entering input??

#include < iostream.h >

#include < stdio.h >

#include < iomanip.h >

int Miles_traveled(double &g);

double Mileage(int mi,double g);

void Display(double mpg);

void main()

{

int miles;

double gallons,miles_per_gallon;

miles = Miles_traveled(gallons);

miles_per_gallon = Mileage(miles,gallons);

Display(miles_per_gallon);

return;

}

int Miles_traveled(double &g)

{

int mi;

cout << "Please enter the number of miles traveled: ";

cin >> mi;

cout << endl;

cout << "Please enter gallons of fuel burned: ";

cin >> g;

cout << endl;

return mi;

}

double Mileage(int mi,double g)

{

return (double)mi / g;

}

void Display(double mpg)

{

cout << setiosflags(ios::fixed) << setprecision(1);

cout << "According to the data that you have provided, your car
is
getting" << mpg << " miles per gallon.";

cout << endl << endl;

cout << "Hit enter to continue." << endl;

getchar();

return;

}

sjopkg
Newbie Poster
4 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

Closing this thread due to violation of our posting guidelines concerning homework on the forums.

Here at Daniweb, we help you troubleshoot your code, not write it for you. We're here to help you learn, not help you cheat.

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You