How to find week day corresponding to number using switch case in C++ Language

Introduction: In previous articles i explained the program for Else if ladder or multiple else if to check the day corresponding to number in C++ Language and Else if ladder or multiple else if to check the month corresponding to number in C++ Language.In this post i have written a program to check the week day corresponding to entered number using switch case statement in C++ Language.The switch statement is a control statement that handles multiple selections by passing control to one of the case statements within its body.
It accepts single input from the user and based on that input executes a particular block of statements. Control passes to the statement whose case constant-expression matches the value of switch (expression).

Let's create a program to understand the concept.
#include<conio.h>
#include<iostream.h>
main()
{
      int num;
      clrscr();
      cout<<"Enter any number between 1 to 7: ";
      cin>>num;
      switch(num)
      {
      case 1:
                   cout<<"Monday";
                   break;
      case 2:
                   cout<<"Tuesday";
                   break;
      case 3:
                   cout<<"Wednesday";
                   break;
      case 4:
                   cout<<"Thursday";
                   break;
      case 5:
                   cout<<"Friday";
                   break;
      case 6:
                   cout<<"Saturday";
                   break;
      case 7:
                   cout<<"Sunday";
                   break;
      default:
                   cout<<"INVALID NUMBER!!! Please enter number between 1 to 7";
      }
      getch();
      }

OUTPUT
First Run:
Enter any number  between 1 to 7: 2
Tuesday

Second  Run:
Enter any number  between 1 to 7: 15
INVALID  NUMBER !!! Please enter number between 1 to 7  
     
Previous
Next Post »

1 comments:

Click here for comments
Unknown
admin
September 11, 2015 ×

How can we do the same program using if-else statement

Congrats bro Unknown you got PERTAMAX...! hehehehe...
Reply
avatar

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..