//Write code that reads an unspecified number of scores and determines how many scores are above or equal
//to the average and how many scores are below the average.
//Enter a negative number to signify the end of the input.Assume that the maximum number of scores is 100.
int[] scores = new int[10];
int count = 0, total = 0;
for(int i = 0; i < scores.Length; i++)
{
Console.Write($"Enter the score: ");
int score = int.Parse(Console.ReadLine());
if (score < 0)
{
break;
}
scores[i] = score;
total += score;
count++;
}
double average = total / count;
int aboveOrEqualToAverage = 0, belowAverage = 0;
for(int i = 0; i < count; i++)
{
if(scores[i] >= average)
{
aboveOrEqualToAverage++;
}
else
{
belowAverage++;
}
}
Console.WriteLine($"Average : {average}");
Console.WriteLine($"Scores above or equal to the average {aboveOrEqualToAverage}");
Console.WriteLine($"Scores below the average: {belowAverage}");
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter