| | |
HOW TO PROGRAM C++ homework
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2004
Posts: 1
Reputation:
Solved Threads: 0
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
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
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.
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.
•
•
•
•
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)
// your code here int main() { // your code here return 0; }
"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
•
•
Join Date: Oct 2004
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Dave Sinkula
C++ Syntax (Toggle Plain Text)
// 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?
•
•
Join Date: Oct 2004
Posts: 4
Reputation:
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;
}
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;
}
![]() |
Similar Threads
- on a simple airline booking program (C)
- Need help for simple program, don't have a clue about C (C)
- pls i need help in this simple program of arrays... (C)
Other Threads in the C++ Forum
- Previous Thread: Dial tone detecting before performing a call!!
- Next Thread: Cube Root
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





