How do you add user input from a sentinel controlled loop in C#?

Home / Uncategorized / How do you add user input from a sentinel controlled loop in C#?

Question:
I have recently started leaning C# (my first C language) and I am at a loss on how to build this program. I am creating a GPA calculator using a sentinel controlled loop. To keep it simple, I am making all of the classes worth 3 credit hours. I would like the user to enter as many grades as they would like, up to 100 (on a scale of 0-4, where A = 4, B = 3, C = 2, D = 1, and F = 0). The biggest problem I am facing is that I can’t figure out how to add each value that the user enters together to determine the grade total. Can anyone help me get on the right track with this? Thanks! -Sandra

Code:class Program
{
static void Main(string[] args)
{

double creditHours = 3.0;
double gradeTotal = 0;
int[] score = new int[100];
string inValue;
int scoreCnt = 0;
Console.WriteLine("When entering grades, use a 0-4 scale. Remember
that A = 4, B = 3, C = 2, D = 1, F = 0");
Console.WriteLine("Enter grade {0}: ((-99 to exit)) ", scoreCnt +
1);
inValue = Console.ReadLine();
gradeTotal = Add.inValue;//This is wrong, but I couldn’t figure out
//the correct way
while (inValue != "-99")
{
if (int.TryParse(inValue, out score[scoreCnt]) == false)
Console.WriteLine("Invalid data -" + "0 stored in array");
++scoreCnt;
Console.WriteLine("Enter Score{0}: ((-99 to exit)) ", scoreCnt +
1);
inValue = Console.ReadLine();
gradeTotal = Add.inValue;//This is also wrong
}
Console.WriteLine("The number of scores: " + scoreCnt);
Console.WriteLine("Your GPA is: " + (gradeTotal / (creditHours *
scoreCnt));//This is also wrong 🙁
Console.ReadLine();
}
}


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *