tags:

views:

604

answers:

3

Programming Student here...trying to work on a project but I'm stuck.

The project is trying to find the miles per gallon per trip then at the end outputting total miles and total gallons used and averaging miles per gallon

How do I loop back up to the first question after the first set of questions has been asked.

Also how will I average the trips...will I have to have a variable for each of the trips? I'm stuck, any help would be great!

+2  A: 

You will have to tell us the type of data you are given.

As per your last question: remember that an average can be calculated in real time by either storing the sum and the number of data points (two numbers), or the current average and the number of data points (again, two numbers).

For instance:

class Averager {
    double avg;
    int n;
public:
    Averager() : avg(0), n(0) {}
    void addPoint(double v) {
        avg = (n * avg + v) / (n + 1);
        n++;
    }
    double average() const { return avg; }
};
Frank Krueger
A: 

Frank: Gallons Used Starting Mileage Ending Mileage Miles Driven

I have some very simplistic pesudocode but I'm almost embarrassed to post it

Andy_Small
A: 
  int num2;
  int num3;
  int num1 ;
while ( num1 < 50 )


{cout << "enter your first number:  ";
cin >> num1;

cout << "Enter your second number:  ";
cin >> num2;

num1 = num1 + num2 ; 

 cout << "Number 1 is now: " << num1 <<endl;

 cout << "Enter Number 3: " ;
 cin >> num3;

 num1 = num1 + num3;

 cout << "Number 1 is now: " << num1 << endl;
 num1 ;
}";

So this loops back but it doesn't hold the num1 data from the two times where num1 was added.

Why not? What I'm I missing?

Andy_Small