how to calculate the average of a student and then calculate the class average using "do while" and "for" in C #? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

how to calculate the average of a student and then calculate the class average using "do while" and "for" in C #?

I know that to calculate the average of each one is like this, but I do not know how to calculate the average of the class: namespace SoloLearn { class Program { static void Main(string[] args) { double notes, totalnotes = 0, average = 0; int cont; for (cont = 0; cont < 4; cont++) { Console.WriteLine("Insert the note: ", cont); notes = Double.Parse(Console.ReadLine()); totalnotes += notes; } average = totalnotes / cont; Console.WriteLine("Your average was: {0}", average); } } }

18th May 2019, 8:43 PM
Thayane Carvalho
Thayane Carvalho - avatar
3 Answers
+ 1
So you want to calculate the results of a student and the result of the entire group (class is a confusing in this context) the student is in. According to the assignment you should use a do while loop A do while loop runs at least one time, and is evaluated at the end of the loop. Do { Console.WriteLine("Press 'N' to enter the result of another student); AnotherStudent = Console.ReadLine(); } While (AnotherStudent == 'N') This is difficult to use in the sololearn playground because you need to put all inputs in before running the code. The fun of average is that you can sum them, divede it by the number of students and have a new average. So make a variable totalaverage and make a variable totalstudents Declare these variables above the do while. if a average of a student is calculate totalaverage += average; also increate the number of students totalstudents++; When the do-while loop is finished. Calculate the average of the group of students Group_average = totalaverage / totalstudents This is pseudo code, please make you own.
19th May 2019, 8:51 PM
sneeze
sneeze - avatar
+ 1
Please explain you question a bit more. I can see you are calculating a average. Where do you try to calculate the second average ?
19th May 2019, 6:54 AM
sneeze
sneeze - avatar
+ 1
Yes, using the first average
19th May 2019, 3:33 PM
Thayane Carvalho
Thayane Carvalho - avatar