Dremendo Tag Line

Menu driven program using switch case in C++

switch case - Question 5

In this question, we will see how to create a menu-driven program in C++ using the switch case statement. To know more about switch case statement click on the switch case statement lesson.

Q5) Write a menu-driven program using the switch case statement in C++ to check whether a number is:

  1. Even number or Odd number
  2. Two digit positive number or not
  3. Multiple of 5 or not

Program

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

using namespace std;

int main()
{
    int c,n;
    cout<<"1 Even number or Odd number\n";
    cout<<"2 Two digit positive number or not\n";
    cout<<"3 Multiple of 5 or not\n";
    cout<<"Enter your choice: ";
    cin>>c;

    switch(c)
    {
        case 1:
            cout<<"Enter a number ";
            cin>>n;
            if(n%2==0)
            {
                cout<<"Even Number";
            }
            else
            {
                cout<<"Odd Number";
            }
            break;

        case 2:
            cout<<"Enter a number ";
            cin>>n;
            if(n>=10 && n<100)
            {
                cout<<"Two digit positive number";
            }
            else
            {
                cout<<"Not two digit positive number";
            }
            break;

        case 3:
            cout<<"Enter a number ";
            cin>>n;
            if(n%5==0)
            {
                cout<<"Multiple of 5";
            }
            else
            {
                cout<<"Not multiple of 5";
            }
            break;

        default:
            cout<<"Invalid Choice";
    }
    return 0;
}

Output

1 Even number or Odd number
2 Two digit positive number or not
3 Multiple of 5 or not
Enter your choice: 2
Enter a number 58
Two digit positive number
video-poster