Find Weekend using Switch Case in C++


This C++ program takes an input of a day's number and uses a switch statement to check whether the entered day is a weekend day or not. Here's how the program works:

  • The program prompts the user to enter the day's number.
  • The user enters a number between 1 and 7, where 1 is Monday and 7 is Sunday.
  • The program uses a switch statement to check which day was entered.
  • If the entered day is 6 or 7, the program outputs that it is a weekend day.
  • If the entered day is not 6 or 7, the program outputs that it is not a weekend day.
  • The break statement is used to end each case statement and prevent the program from executing subsequent case statements.
  • Finally, the program returns 0 to indicate successful execution.

Overall, this program is a good example of how to use a switch statement in C++ to handle multiple cases. However, it could be improved by adding input validation to check that the entered day number is within the correct range of 1 to 7. Additionally, it could be modified to output the day's name instead of a statement about the weekend.

Source Code

#include<iostream>
using namespace std;
int main()
{
    int day;
    cout<<"\nEnter the Day's number :";
    cin>>day;
    switch(day)
    {
      case 6:
        cout<<"\nToday is Saturday";
        break;
      case 7:
        cout<<"\nToday is Sunday";
        break;
      default:
        cout<<"\nLooking forward to the Weekend";
    }
    return 0;
}
To download raw file Click Here

Output

Enter the Day's number :5
Looking forward to the Weekend

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples