Answer to Question #324593 in C++ for Secret Agent

Question #324593

Odd-Even-inator

by CodeChum Admin

My friends are geeking out with this new device I invented. It checks if a number is even or odd! 🤯


Do you want to try it out?


Instructions:

  1. In the code editor, you are provided with a function that checks whether a number is even or odd.
  2. Your task is to ask the user for the number of integer, n, they want to input and then the actual n number values. For each of the number, check whether it is even or odd using the function provided for you.
  3. Make sure to print the correct, required message.

Input


1. Integer n

2. N integer values

Output


Enter·n:·5
Enter·value·#1:·3
3·is·odd
Enter·value·#2:·6
6·is·even
Enter·value·#3:·4
4·is·even
Enter·value·#4:·1
1·is·odd
Enter·value·#5:·3
3·is·odd
1
Expert's answer
2022-04-07T13:13:47-0400
#include <iostream>
#include <string>

using namespace std;

string OddOrEven(int val)
{
	if (val % 2 == 0)
		return "even";
	else
		return "odd";
}

int main()
{
	int n;
	cout << "Enter n: ";
	cin >> n;
	int val;
	for (int i = 0; i < n; i++)
	{
		cout << "Enter value #" << i + 1 << ": ";
		cin >> val;
		cout << val << " is " << OddOrEven(val)<<endl;
	}
}

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
APPROVED BY CLIENTS