Hi I was wondering if someone could explain how to to make this method diplay a running count and average, and not just display it once the user has finished entering its data?
public void InScreen()
{
int count = 0;
double total = 0.0;
double average = 0.0;
double number;
Console.WriteLine("Enter the set of scores (enter 0 to indicate end of set)");
number = double.Parse(Console.ReadLine());
while(number != 0)
{
total += number;
count++;
number = double.Parse(Console.ReadLine());
}
if (count != 0)
average = total / count;
Console.Beep(20000, 2000);
Console.WriteLine("The user has entered {0} scores.", count);
Console.WriteLine("The sum of scores entered = {0}", total);
Console.WriteLine("The average of scores entered = {0}", average);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…