SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Barbara Dolye
Chapter:
Data Types And Expressions
Exercise:
Programming Exercises
Question:6 | ISBN:9781285096261 | Edition: 4

Question

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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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

 

0 0

Discussions

Post the discussion to improve the above solution.