Answer to Question #253802 in C# for Kayla

Question #253802
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.
1
Expert's answer
2021-10-20T00:54:47-0400
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double average;
            double sum = 0;
            double score = 1;
            double totalScores = 0;


            while (true)
            {
                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))
                {
                    Console.WriteLine("Going out");
                    break;
                }
                sum += score;
                totalScores++;
            }
            
            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();
        }


    }
}

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