HOW TO PROGRAM C++ homework

Please support our C++ advertiser: Intel Parallel Studio Home
Closed Thread

Join Date: Aug 2004
Posts: 1
Reputation: NitrousGT is an unknown quantity at this point 
Solved Threads: 0
NitrousGT NitrousGT is offline Offline
Newbie Poster

HOW TO PROGRAM C++ homework

 
0
  #1
Aug 3rd, 2004
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
Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: HOW TO PROGRAM C++ homework

 
0
  #2
Aug 4th, 2004
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.

Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Quick reply to this message  
Join Date: Oct 2004
Posts: 4
Reputation: sjopkg is an unknown quantity at this point 
Solved Threads: 0
sjopkg sjopkg is offline Offline
Newbie Poster

Re: HOW TO PROGRAM C++ homework

 
0
  #3
Oct 20th, 2004
I also need help getting started on this same program. But I don't even know where to start...
any help would be great!
Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: HOW TO PROGRAM C++ homework

 
0
  #4
Oct 21st, 2004
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!
  1. // your code here
  2.  
  3. int main()
  4. {
  5. // your code here
  6. return 0;
  7. }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Quick reply to this message  
Join Date: Oct 2004
Posts: 4
Reputation: sjopkg is an unknown quantity at this point 
Solved Threads: 0
sjopkg sjopkg is offline Offline
Newbie Poster

Re: HOW TO PROGRAM C++ homework

 
0
  #5
Oct 24th, 2004
Originally Posted by Dave Sinkula
  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?
Quick reply to this message  
Join Date: Oct 2004
Posts: 4
Reputation: sjopkg is an unknown quantity at this point 
Solved Threads: 0
sjopkg sjopkg is offline Offline
Newbie Poster

Re: HOW TO PROGRAM C++ homework

 
0
  #6
Oct 25th, 2004
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;

}
Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: HOW TO PROGRAM C++ homework

 
0
  #7
Oct 26th, 2004
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.
Alex Cavnar, aka alc6379
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC