+ 3

How to find out class total and average using arrays? Please see the code which i have inserted and help me please.

Here is the c++ code which i have constructed. please look into the code and help me by telling what should i do to make the class total at last correct. https://code.sololearn.com/cRefkGQwRFni/?ref=app

18th May 2017, 5:48 AM
Harsh
Harsh - avatar
11 Réponses
+ 2
Hey @Harsh, it took me a little while, but I made a few adjustments. In short, you were printing out each iteration of the sum side-by-side. The cout<<sum should come after the loop. I took the liberty of making a few other changes as well. https://code.sololearn.com/cRlD23oxzz2b/ It works good in my console view (though not great on the sololearn Code Playground.
18th May 2017, 7:50 AM
Joseph P French
Joseph P French - avatar
+ 5
@Harsh: By sample input I mean what you would enter as a mark for each class and what you would expect the correct output from the program should be. This is very helpful information to others who are trying to debug your program. But it seems correct to me now as it added both student total scores for me at program termination.
18th May 2017, 7:30 AM
jay
jay - avatar
+ 4
+ If you exit the program early you will be advancing further into the array than there is data. To solve this you need to add a counter to determine how many entries were actually made, rather than relying on the user input. Also, your initial loop condition is incorrect. As well as the final loop condition.. Both go too long. Since it starts counting at 0, when a user enters 1, the loop executes twice. I have made the changes required to get it working correctly https://code.sololearn.com/cx8IKX2rtTlt/#cpp Please have a look through at the changes and how they affect the program operation.
18th May 2017, 7:23 AM
jay
jay - avatar
+ 3
@Harsh; Can you provide a sample input for a student
18th May 2017, 6:59 AM
jay
jay - avatar
+ 3
To make the program more user friendly I would move the inputs for marks under each prompt. For example. cout << "\n\n Enter your marks in maths="; cin >> a[x]; cout << "\n\n Enter your marks in science="; cin >> b[x];
18th May 2017, 7:03 AM
jay
jay - avatar
+ 2
Thank you @Joseph for your wonderful effort to help
18th May 2017, 7:58 AM
Harsh
Harsh - avatar
+ 1
Thats very good idea. But how do i calculate the class total. roll up please , i have described it
18th May 2017, 7:07 AM
Harsh
Harsh - avatar
+ 1
Thanxx @jay
18th May 2017, 7:58 AM
Harsh
Harsh - avatar
0
Seems to be working for me when I run it in a console, but the 'cout' asking for the inputs does not work until after you make the inputs... not sure why. Otherwise, this works fine with up to four students for me. It does round the percentage to the nearest whole number. Were you trying to get a percentage for the class? Divide the sum by 450 and multiply by 100.
18th May 2017, 6:34 AM
Joseph P French
Joseph P French - avatar
0
see at last @joseph , down of lb: it is written that sum=sum+total[x]; but the problem is the sum equals to only one value for x . I want to find out the class total that is for all the values of x.What should i do ??
18th May 2017, 6:42 AM
Harsh
Harsh - avatar
0
i have inserted it @jay
18th May 2017, 7:00 AM
Harsh
Harsh - avatar