Caroline Ininga

A Calculator App to get the Average of Scores in C#

//This console application is for helping the teacher get the average of score of thier student’s scores

int currentscore; //currentscore variable is initialized, default value is zero
int sum = 0; //variable sum is intitialized, default value is zero
int counter= 0; //variable counter is initialized, default value is zero
do
{
Console.WriteLine(“Enter your students score. Enter -1 to finish!”); // the console prompts the teacher to enter the students scores
currentscore = int.Parse(Console.ReadLine()); // the teacher’s value is converted to an interger
if (currentscore!= -1) /*the if statement here ensures that the sum and counter variables is increased by
* currentscore value only if it is not -1, if the user enters -1, sum and counter variables will not change */
{
sum = sum + currentscore;
counter++;
}

}
while (currentscore != -1); /*As long as this condition is true, meaning currentscore is not -1, the loop will continue and
* whatever is inside the do will run again. */
int average = sum / counter; // this will be executed when the condition inside the while is false, meaning currenscore is -1 to get the average

Console.WriteLine(“The average is:” + average); //the user will get the average of the scores entered



Leave a Reply