How to calculate average?

Mar 19, 2009 at 7:27pm
Can anyone tell me how to calculate average in a C++ program for e.g average of numbers?

I have used the following code:
Average=0
Average+=Marks_Eng+Marks_Hin+Marks_Math+Marks_Sci%4;

This does not give me correct output.
Last edited on Mar 19, 2009 at 7:34pm
Mar 19, 2009 at 7:57pm
% (modulo) finds the remainder.
http://en.wikipedia.org/wiki/Modulo_operator

Use division instead.

EDIT: Deleted later reply as jdd beat me to it.
Last edited on Mar 19, 2009 at 8:14pm
Mar 19, 2009 at 8:02pm
done that...does not work...
Mar 19, 2009 at 8:03pm
Also keep in mind the order of operations. Division (or modulo) happens before addition. You need to group the items being averaged.

Average = ( num1 + num2 + ... numn ) / n
Mar 19, 2009 at 8:07pm
thanks jdd...it worked:-)...i will keep this in mind...
Mar 19, 2009 at 8:08pm
thanks chungolongo!
Topic archived. No new replies allowed.