Write a program in C++ using the switch case to print the Equivalent name of the day on the basis of user input

By | August 27, 2019

In this program, we will code to print out the week’s day on the basis of user input from 1 to 7. Here 1 represent Sunday, 2 represent Monday and so on.

Here we will ask the user to enter a number from range 1 to 7 and show the day equivalent to that number.

C++ Program to print the weekday using switch case:

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int num;
cout<<"Enter a number from 1 to 7: ";
cin>>num;
while(1)
   {
   if(num <1 || num>7)
      {
       cout<<"Please enter a valid number from 1 to 7: ";
       cin>>num;
      }
   else
      break;
   }

switch(num)
    {
    case 1:
    cout<<"Its Sunday";
    break;

    case 2:
    cout<<"Its Monday";
    break;

    case 3:
    cout<<"Its Tuesday";
    break;

    case 4:
    cout<<"Its Wednesday";
    break;

    case 5:
    cout<<"Its Thursday";
    break;


    case 6:
    cout<<"Its Friday";
    break;

    case 7:
    cout<<"Its Saturday";
    break;
    }

getch();
}  

OUTPUT:

Enter a number from 1 to 7: 10
Please enter a valid number from 1 to 7: 4
Its Wednesday

Leave a Reply

Your email address will not be published. Required fields are marked *