Q:

Write C++ program to print day of week name using switch case

0

Write C++ program to print day of week name using switch case

All Answers

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

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.

#include <iostream>
 
using namespace std;
 
int main()
{
    int weeknumber;
 
   //Reading week no from user
   cout<<"Enter week number(1-7): ";
   cin>>weeknumber;
 
    switch(weeknumber)
    {
        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 input! Please enter week no. between 1-7.";
    }
 
    return 0;
 
}

Result:

Enter week number(1-7): 5

Friday

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

total answers (1)

Write C++ program to create simple calculator usin... >>
<< Write C++ program to print number of days in a mon...