Answer to Question #42930 in C++ for Amit malik

Question #42930
Write a programe that inputs an integer between 1 and 10 and use a switch statement to determine odd no. And the no. Which are a multiple of 4, otherwise the switch statement should inform the user that the entered no. Is neither even nor multiple of 4.
The programe should be repeated until the user enters -1, use a do while statement for repeat part
1
Expert's answer
2014-06-04T10:36:25-0400
#include<iostream>
using namespace std;
int main()
{
bool b = true;
int x;
do
{
cout << "Enter number from 1 to 10 (for EXIT type -1):";
cin >> x;
switch(x)
{
case -1:
b = false;
break;
case 1:
cout << "Neither even, nor multiple of 4\n";
cout << "\n";
break;

case 2:
cout << "Even, but not a multiple of 4\n";
cout << "\n";
break;

case 3:
cout << "Even, but not a multiple of 4\n";
cout << "\n";
break;

case 4:
cout << "Not even, but a multiple of 4\n";
cout << "\n";
break;

case 5:
cout << "Even, but not a multiple of 4\n";
cout << "\n";
break;

case 6:
cout << "Neither even, nor multiple of 4\n";
cout << "\n";
break;

case 7:
cout << "Even, but not a multiple of 4\n";
cout << "\n";
break;

case 8:
cout << "Not even, but a multiple of 4\n";
cout << "\n";
break;

case 9:
cout << "Neither even, nor multiple of 4\n";
cout << "\n";
break;

case 10:
cout << "Neither even, nor multiple of 4\n";
cout << "\n";
break;

default:
cout << "Please enter number from 1 to 10!\n";
cout << "\n";
break;

}
}while(b);
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS