Write a program that computes the average of five exam scores. Declare and
perform a compile-time initialization with the five values. Use a constant to
define the number of scores. Print all scores and the average value formatted
with no digits to the right of the decimal. Rerun the application with different
values.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExamScore
{
// Create a class named ExamScore
class ExamScore
{
// Create a main method to run the program
static void Main(string[] args)
{
// Declare a Constant Int variable named numberOfScores to store the Number Of Scores .
const int numberOfScores = 5;
// Declare a double variable named examScore1 to store the Exam Score 1.
double examScore1 = 84;
// Declare a double variable named examScore1 to store the Exam Score 2.
double examScore2 = 86;
// Declare a double variable named examScore1 to store the Exam Score 3.
double examScore3 = 89;
// Declare a double variable named examScore1 to store the Exam Score 4.
double examScore4 = 93;
// Declare a double variable named examScore1 to store the Exam Score 5.
double examScore5 = 96;
// Declare a double variable named average to store the Average.
double average;
//logical formula for average
//average=(examScore1+examScore2+examScore3+examScore4+examScore5)/numberOfScores;
average = (examScore1 + examScore2 + examScore3 + examScore4 + examScore5) / numberOfScores;
//display the output
Console.WriteLine("Exam Score 1 : " + "{0:f2}", +examScore1);
Console.WriteLine("Exam Score 2 : " + "{0:f2}", +examScore2);
Console.WriteLine("Exam Score 3 : " + "{0:f2}", +examScore3);
Console.WriteLine("Exam Score 4 : " + "{0:f2}", +examScore4);
Console.WriteLine("Exam Score 5 : " + "{0:f2}", +examScore5);
Console.WriteLine("Total Average : " + "{0:0}", +average);
}
}
}
Output:
Exam Score 1 : 84.00
Exam Score 2 : 86.00
Exam Score 3 : 89.00
Exam Score 4 : 93.00
Exam Score 5 : 96.00
Total Average : 90