C# program to read student's grade and display the equivalent description

Here we will create a program to read the grade of students from the keyboard and print the appropriate description of grade. By Nidhi Last updated : April 15, 2023

Following are the grades and description,

Grade		    Description
A		    Excellent 
B		    Very Good
C		    Good
D		    Keep it up
E		    Poor
F		    Very Poor	

Read student's grade and display the equivalent description in C#

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.

C# Basic Programs »


Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.