All Type Coding

Search Here

Write a switch case statement program in c#.?



using System;

class Program
{
    static void Main(string[] args)
    {
        /* local variable definition */

        Start: Console.WriteLine("Enter your grade");
    
        char grade = Convert.ToChar(Console.ReadLine());
        //char grade = 'B';

        switch (grade)
        {
            case 'A':
                Console.WriteLine("Excellent!");
                break;
            case 'B':
            case 'C':
                Console.WriteLine("Well done");
                break;
            case 'D':
                Console.WriteLine("You passed");
                break;
            case 'F':
                Console.WriteLine("Better try again");
                break;
            default:
                Console.WriteLine("Invalid grade");
                break;
               
        }
        Console.WriteLine("Your grade is  {0}", grade);       
        Console.ReadLine();
        goto Start;
    }
}


When the above code is compiled and executed, it produces the following result:


No comments :

Post a Comment