Sep 23, 2016 at 12:28pm UTC
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;
Sep 23, 2016 at 12:58pm UTC
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 Sep 23, 2016 at 1:03pm UTC
Sep 23, 2016 at 1:41pm UTC
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 Sep 23, 2016 at 1:43pm UTC
Sep 27, 2016 at 9:32am UTC
thank you, boost lexical cast and krako