Q:

C# program to input weekday number and print the weekday

0

C# program to input weekday number and print the weekday

All Answers

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

C# code to print weekday name from given weekday number (0-6)

Here, we are asking for an input of the weekday number (from 0 to 6) and print the weekday based on the given input using switch statement.

// C# program to input weekday number and print the weekday
using System;
using System.IO;
using System.Text;

namespace IncludeHelp
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            int wday;

            //input wday number
            Console.Write("Enter weekday number (0-6): ");
            wday = Convert.ToInt32(Console.ReadLine());

            //validating using switch case
            switch (wday)
            {
                case 0:
                    Console.WriteLine("It's SUNDAY");
                    break;
                case 1:
                    Console.WriteLine("It's MONDAY");
                    break;
                case 2:
                    Console.WriteLine("It's TUESDAY");
                    break;
                case 3:
                    Console.WriteLine("It's WEDNESDAY");
                    break;
                case 4:
                    Console.WriteLine("It's THURSDAY");
                    break;
                case 5:
                    Console.WriteLine("It's FRIDAY");
                    break;
                case 6:
                    Console.WriteLine("It's SATURDAY");
                    break;
                
                //if no case value is matched
                default:
                    Console.WriteLine("It's wrong input...");
                    break;
            }

            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}

Output

First run:
Enter weekday number (0-6): 0
It's SUNDAY

Second run:
Enter weekday number (0-6): 4
It's THURSDAY

Third run:
Enter weekday number (0-6): 6
It's SATURDAY

Fourth run:
Enter weekday number (0-6): 9
It's wrong input...

 

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

total answers (1)

C# | Design a simple calculator using if else if s... >>
<< C# program to check given strings are equal or not...