Answer to Question #12112 in C# for Nicole

Question #12112
A program to read in a list of test scores and output the highest score,the lowest score, and the average score.
1
Expert's answer
2012-07-20T11:25:19-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TEMP
{
class Program
{
& static void Main(string[] args)
& {
int n = 0;
List<int> scores = new List<int>();
Console.Write("Enter number of scores: ");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter " + n.ToString() + " scores");
for (int i = 0; i < n; i++)
{
Console.Write((i + 1).ToString() + ". ");
int temp = int.Parse(Console.ReadLine());
scores.Add(temp);
}

int min = int.MaxValue;
int max = int.MinValue;
int sum = 0;
double average;

foreach (int t in scores)
{
if (t > max)
& max = t;
if (t < min)
& min = t;
sum += t;
}
average = sum / n;
Console.WriteLine(" The higest score: " + max.ToString());
Console.WriteLine(" The lowest score: " + min.ToString());
Console.WriteLine("The average score: " + average.ToString());
Console.ReadLine();
& }
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS