Answer:
It's always good to use if else with boolean expressions in such cases.
Explanation:
I have written a program where I have used c# as programming language.
I used if else block with boolean expressions to enforce conditions to print the grades according to the average of test scores. I have used Logical And(&&) operator in boolean expressions so that all the conditions in if and if else must be true
Here is the program:
using System;
public class Test
{
public static void Main()
{
int testScore1, testScore2, testScore3;
Console.WriteLine("enter first testScore");
testScore1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter second testScore");
testScore2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter third testScore");
testScore3 = Convert.ToInt32(Console.ReadLine());
float avg = (testScore1 + testScore2 + testScore3) / 3;
if(avg>=90)
{
Console.WriteLine("You got grade A");
}
else if(avg >=80 && avg <=89)
{
Console.WriteLine("You got grade B");
}
else if (avg >= 70 && avg <= 79)
{
Console.WriteLine("You got grade c");
}
else if (avg >= 60 && avg <= 69)
{
Console.WriteLine("You got grade D");
}
else if(avg< 60)
{
Console.WriteLine("You got grade E");
}
else
{
Console.WriteLine("Sorry, You failed");
}
Console.ReadLine();
}
}
Explanation of program:
I created three variables named, testScore1, testScore2, testScore3 of datatype int. I prompted the user to enter three test score values. Each value is read using Console.ReadLine() . As the value entered is of type integer, I converted the console read value into int using Convert method.
In the next step, I calculated average using the formula.
Now, Based on the average, I can calculate the grade according to the given grading scheme.