Answer to Question #299888 in C++ for saim sikandar

Question #299888

write a Program to check whether a number is divisible by 5 and 11 or not. Using the switch statement

1
Expert's answer
2022-02-20T14:40:54-0500
#include<iostream>

using namespace std;

int main()
{
	int value;
	do
	{
		char state='0';
		cout << "\nPlease, enter a value(0 - break): ";
		cin >> value;
		if (value % 5 == 0)
		{
			state = '1';
		}
		if (value % 11 == 0)
		{
			state = '2';
		}
		if ((value % 11 == 0)&& (value % 5 == 0))
		{
			state = '3';
		}
		if (value == 0)break;
		switch (state)
		{
			case '0':
			{
				cout << value << " is not divisible by 5 and 11";
				break;
			}
			case '1':
			{
				cout << value << " is only divisible by 5";
				break;
			}
			case '2':
			{
				cout << value << " is only divisible by 11";
				break;
			}
			case '3':
			{
				cout << value << " is divisible by 5 and 11";
				break;
			}
		}
	} while (true);
}

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

saim
20.02.22, 21:47

best website ever..solve all my problems thanks

Leave a comment

LATEST TUTORIALS
New on Blog