looping and average in c++

Question :

looping and average in c++,

Answer :

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!

Read More  Securing a linux webserver for public access

,

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

That’s the answer looping and average in c++, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Read More  How can I turn a string of HTML into a DOM object in a Firefox extension?

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you