Answer to Question #253032 in C# for Israel

Question #253032

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-19T15:20:18-0400
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();
        }


    }
}

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
New on Blog
APPROVED BY CLIENTS