943,628 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4252
  • C++ RSS
Aug 3rd, 2004
0

HOW TO PROGRAM C++ homework

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NitrousGT is offline Offline
1 posts
since Aug 2004
Aug 4th, 2004
0

Re: HOW TO PROGRAM C++ homework

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.

Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Oct 20th, 2004
0

Re: HOW TO PROGRAM C++ homework

I also need help getting started on this same program. But I don't even know where to start...
any help would be great!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sjopkg is offline Offline
4 posts
since Oct 2004
Oct 21st, 2004
0

Re: HOW TO PROGRAM C++ homework

Quote originally posted by sjopkg ...
I also need help getting started on this same program. But I don't even know where to start...
any help would be great!
C++ Syntax (Toggle Plain Text)
  1. // your code here
  2.  
  3. int main()
  4. {
  5. // your code here
  6. return 0;
  7. }
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Oct 24th, 2004
0

Re: HOW TO PROGRAM C++ homework

Quote originally posted by Dave Sinkula ...
C++ Syntax (Toggle Plain Text)
  1. // your code here
  2.  
  3. int main()
  4. {
  5. // your code here
  6. return 0;
  7. }

How would you begine writing the code...is there a certain format or steps to take in order to compile the program?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sjopkg is offline Offline
4 posts
since Oct 2004
Oct 25th, 2004
0

Re: HOW TO PROGRAM C++ homework

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;

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sjopkg is offline Offline
4 posts
since Oct 2004
Oct 26th, 2004
0

Re: HOW TO PROGRAM C++ homework

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.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: Dial tone detecting before performing a call!!
Next Thread in C++ Forum Timeline: Cube Root





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC