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

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:

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

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;
 }
// 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?

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;
}

Edited 3 Years Ago by pyTony: fixed formating

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.

This article has been dead for over six months. Start a new discussion instead.