In: Computer Science
Open Average Test Scores while loop, comment out the while loop and add a for loop that averages 4 test scores. Code C#
While loop code
using System;
class Program
{
static void Main() {
int count = 0, total = 0, number;
while (count < 3)
{
Console.Write("Enter a number: ");
number = Convert.ToInt32(Console.ReadLine());
total += number;
count++;
}
double average = total / 3.0;
Console.Write("Average = " + average.ToString("####0.00"));
}
}
using System;
class Program
{
static void Main() {
int count = 0, total = 0, number;
for(count = 0; count <4; count++) // loops 4
times
{
Console.Write("Enter a number: ");
number = Convert.ToInt32(Console.ReadLine());
total += number;
}
double average = total / 4.0;
Console.Write("Average = " + average.ToString("####0.00"));
}
}
// Hit the thumbs up if you are fine with the answer.
Happy Learning!