Write a program to allow multiple sets of scores to be averaged. Valid entries must be numeric and in the range of 0 to 100. Calculate the average of the scores entered. Allow any number of scores to be entered per data set but assume that there will be at least one score entered. Use a sentinel-controlled loop variable to terminate the loop. After values are entered and average is calculated, test the average to determine whether an A, B, C, D or F should be recorded. The scoring rubric is as follows: A: 90 to 100; B80 to 89; C 70 to 79; D 60 to 69 and F <60.
using System;
using System.Collections.Generic;
namespace App
{
class Program
{
static void Main(string[] args)
{
double average;
double sum = 0;
double score = 1;
double totalScores = 0;
while (score >= 0 && score <= 100)
{
// Valid entries must be numeric and in the range of 0 to 100
Console.Write("Enter score in the range of 0 to 100 (-1 to exit): ");
double.TryParse(Console.ReadLine(), out score);
if (score >= 0 && score <= 100)
{
sum += score;
totalScores++;
}
}
// After values are entered and average is calculated, test the average to determine
//whether an A, B, C, D or F should be recorded.
//The scoring rubric is as follows: A: 90 to 100; B80 to 89; C 70 to 79; D 60 to 69 and F <60.
average = sum / totalScores;
Console.WriteLine("Average: {0}", average);
if (average >= 90 && average <= 100)
{
Console.WriteLine("Grade: A");
}
else if (average >= 80 && average <= 89)
{
Console.WriteLine("Grade: B");
}
else if (average >= 70 && average <= 79)
{
Console.WriteLine("Grade: C");
}
else if (average >= 60 && average <= 69)
{
Console.WriteLine("Grade: D");
}
else
{
Console.WriteLine("Grade: F");
}
Console.ReadLine();
}
}
}
Comments
Leave a comment