Q:

C# program to read the grade of students and print the appropriate description of grade

belongs to collection: C# Basic Programs | basics

0

C# program to read the grade of students and print the appropriate description of grade

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to print the description of the specified grade in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

// Program to read grade of the student from the keyboard 
// and print appropriate description of grade.

using System;

class GradeDemo
{
    public static void Main()
    {
        char student_grade;

        Console.Write("Enter the student grade: ");
        student_grade = Convert.ToChar(Console.ReadLine());

        switch (student_grade)
        {
            case 'A':
                Console.WriteLine("Excellent");
                break;
            case 'B':
                Console.WriteLine("Very Good");
                break;
            case 'C':
                Console.WriteLine("Good");
                break;
            case 'D':
                Console.WriteLine("Keep it up");
                break;
            case 'E':
                Console.WriteLine("Poor");
                break;
            case 'F':
                Console.WriteLine("Very Poor");
                break;
            default:
                Console.WriteLine("Invalid GRADE");
                break;
        }
    }
}

Output:

Enter the student grade: C
Good
Press any key to continue . . .

Explanation:

In the above program, we created a GradeDemo class that contains the Main() method. Here we created the variable student_grade of character type.

Console.Write("Enter the student grade: ");
student_grade = Convert.ToChar(Console.ReadLine());

In the above statements we took grade as input using ReadLine() method and then convert it into single character using ToChar() method, because ReadLine() method takes string as a input. 

After that, we matched input grade using switch-case and print the appropriate description on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to calculate the size of the area in sq... >>
<< C# program to demonstrate the example of the left-...