Answer to Question #299592 in C++ for yohannes

Question #299592

write a c++program ether even or odd


1
Expert's answer
2022-02-18T15:23:25-0500
#include<iostream>


using namespace std;


int main()
{
	int value;
	do
	{
		char c;
		cout << "Please, enter a value: ";
		cin >> value;
		cout << "\nE - output even"
			<< "\nO - output odd"
			<< "\n0 - exit program";
		cout << "\nYour select: ";
		cin >> c;
		if (c == '0')break;
		switch (c)
		{
			case 'E':case 'e':
			{
				for (int i = 0; i <= value; i++)
				{
					if (i % 2 == 0)
					{
						cout << i << " ";
					}	
				}
				cout << endl;
				break;
			}
			case 'O':case 'o':
			{
				for (int i = 0; i <= value; i++)
				{
					if (i % 2 == 1)
					{
						cout << i << " ";
					}	
				}
				cout << endl;
				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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog