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

Here we will create a program to read the grade of students from the keyboard and print the appropriate description of grade.
Submitted by Nidhi, on August 18, 2020

Following are the grades and description,

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

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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.