switch statement

hey guys i sort of need help on how one can use the switch statement in a case like below where the code is given in else if conditional structure..

int x;
cout << "input the value of x :";
cin >> x;
if(x == 1) cout << " It's a busy day!" << endl;
else if(x == 3 || x ==4) cout << "Good!" << endl;
else cout << "All right!" << endl;
closed account (LA48b7Xj)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int x;
cout << "input the value of x :";
cin >> x;

switch(x)
{
	case 1:
		cout << " It's a busy day!" << endl;
		break;
	case 3:
	case 4:
		cout << "Good!" << endl;
		break;
	default:
		cout << "All right!" << endl;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

int main()
{
    int x;
    std::cout << "Input the value of x: ";
    std::cin >> x;

    switch (x)
    {
        case 1:
          std::cout << "It's a busy day!" << std::endl;
          break;
        case 3:
          std::cout << "Good!" << std::endl;
          break;
        case 4:
          std::cout << "Good!" << std::endl;
          break;
        default:
          std::cout << "Alright!" << std::endl;
          break;
    }

    return 0;
}
Last edited on
thank you, boost lexical cast and krako
Topic archived. No new replies allowed.