Rewrite the following program using switch statements.
//Set 7.1
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int x;
cout << "Selection option " << endl;
cin >> x;
if (x == 1)
cout << "You select option 1" << endl;
else if (x >= 2 || x <= 4)
cout << "You select options 2 or 3 or 4" << endl;
else if (x == 10)
cout << "You select option 10" << endl;
else
cout << "You selected incorrect option" << endl;
return 0;
}
#include <iostream> #include <iomanip> using namespace std; int main() { int x; cout << "Selection option " << endl; cin >> x; switch (x) { case 1: cout << "You select option 1" << endl; break; case 2: case 3: case 4: cout << "You select options 2 or 3 or 4" << endl; break; case 10: cout << "You select option 10" << endl; break; default: cout << "You selected incorrect option" << endl; break; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.