+ 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
11 odpowiedzi
+ 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.
+ 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.
+ 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.
+ 3
@Harsh; Can you provide a sample input for a student
+ 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];
+ 2
Thank you @Joseph for your wonderful effort to help
+ 1
Thats very good idea.
But how do i calculate the class total.
roll up please , i have described it
+ 1
Thanxx @jay
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.
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 ??
0
i have inserted it @jay