C# Write a program that computes the average of five exam scores

I am doing my homework. English is not my first language, so I am confused.

This is the question: Write a program that computes the average of five exam scores. Declare and perform a compile-time initialization with the five exam values. Declare integer memory locations for the exam values. Use an integer constant to define the number of scores. Print all scores. The average value should be formatted with two digits to the right of the decimal. Rerun the application with different values. Be sure to desk check your results.

I am not sure what is "a compile-time initialization" mean? What is "Declare integer memory locations for the exam values." want me to do? What is "desk check" mean?

Here is my c# code:

using System;
using static System.Console;

namespace Chap2_1
{
    class Chap2_1
    {
        static void Main()
        {
            int score1;
            int score2;
            int score3;
            int score4;
            int score5;
            double average;

            Console.Write("Please enter the 1st score: ");
            score1 = Convert.ToInt32(Console.ReadLine());
            Console.Write("Please enter the 2nd score: ");
            score2 = Convert.ToInt32(Console.ReadLine());
            Console.Write("Please enter the 3rd score: ");
            score3 = Convert.ToInt32(Console.ReadLine());
            Console.Write("Please enter the 4th score: ");
            score4 = Convert.ToInt32(Console.ReadLine());
            Console.Write("Please enter the 5th score: ");
            score5 = Convert.ToInt32(Console.ReadLine());

            average = (score1+score2+score3+score4+score5) /5;

            Console.Write("Average score is " + "{0:N2}", average);

            Console.ReadKey();
        }
    }
}

Shouldn't these be questions for your teacher? Your teacher will know your struggles and be able to help you far better than any of us simply because of his/her role in your studies.

That said, a compile-time initialization is something like:

int[] scores = new int[] { 100,80,90,64,72 };

or:

int score1 = 100;
int score2 = 80;
int score3 = 90;
int score4 = 64;
int score5 = 72;

As far as the memory locations go, I'd recommend reading Microsoft's C# programming guide here about it:

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/unsafe-code-pointers/how-to-obtain-the-address-of-a-variable

Oh, and "desk check" means to do the same calculations manually with pen and paper to validate that you get the same results as your code.

0 Comment

NO COMMENTS

LEAVE A REPLY

Captcha image