0

How I compute average marks from array of objects ?

https://code.sololearn.com/cfCidEAIZsdL/?ref=app

22nd Feb 2020, 6:03 AM
Muhammad Bilal
Muhammad Bilal - avatar
4 Antworten
+ 4
Declare a double variable before the loop. During loop sum all marks to this variable. After divide the sum(variable) by 5 or by the array's length if you plan to add more elements.
22nd Feb 2020, 6:23 AM
Mihai Apostol
Mihai Apostol - avatar
+ 2
Thanks
22nd Feb 2020, 6:38 AM
Muhammad Bilal
Muhammad Bilal - avatar
+ 1
As a side note, it might be better to use a floating point type for the <student_marks> field. Use of int for average isn't really a good idea, because average is supposedly a percentage value : )
22nd Feb 2020, 6:31 AM
Ipang
0
Muhammad Bilal You're welcome.
22nd Feb 2020, 6:40 AM
Mihai Apostol
Mihai Apostol - avatar