I would go for a switch statement rather than a bunch of if...else statements.
Something like:
switch (desiredGrade.ToLower()) {
case "a":
finalOverallScore = 90;
break;
case "b":
finalOverallScore = 80;
break;
case "c":
finalOverallScore = 70;
break;
case "d":
finalOverallScore = 60;
break;
case "e":
finalOverallScore = 50;
break;
case "f":
finalOverallScore = 0;
break;
default:
throw new ArgumentException("Wrong grade", nameof(desiredGrade));
}
As for knowing why your variable does not get the correct value, you will have to put a breakpoint on the first line of the method and debug to see why. It could be that
desiredGrade
is not A, a, B, b, C, c, D, d, F nor f.
Note: I added the "e" case which you did not seem to have taken into account.
Note 2: transforming the value to lower case allows you to have fewer conditions to test.
Most important thing to understand here is that you have to
debug your code to understand why it does not behave like you would expect it to.
Kindly.