Ask Question
13 March, 02:32

Write a program to define three variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test scores and the letter grade that is assigned for the test score average. Use the grading scheme in the following table. 90 or greater 80-89 70-79 60-69 Below 60

+4
Answers (1)
  1. 13 March, 05:13
    0
    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program to define three variables to hold three test scores. The program should ask the user to enter three test scores and then ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers