Question: What am I missing in my code? Question: Functions can return a string, not just an int or a float. Write a function called evenOrOdd

What am I missing in my code?

Question:

Functions can return a string, not just an int or a float. Write a function called evenOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the given template to get started. Use the following run as an example:

Enter a number: 1 is Odd Enter a number: 2 is Even Enter a number: 3 is Odd Enter a number: 4 is Even Enter a number: 5 is Odd Enter a number: 0 

Code:

#include #include using namespace std; string evenOrOdd(int number) { string answer; if ((number % 2) == 0) { answer = "Even"; } else { answer = "Odd"; } return answer; } int main() { string answer; int number = 1; while (number != 0) { cout>number;

cout

Output:

What am I missing in my code? Question: Functions can return a

1 Compare output 3 input Enter a number: 1 is Odo Enter a number: 2 is Even Enter a number: 3 is Odd Your output Enter a number: 4 is Even Enter a number: 5 is Odd Enter a number: 0 Enter a number: 1 is Odo Enter a number: 2 is Even Enter a number: 3 is Odd Expected output Enter a number: 4 is Even Enter a number: 5 is Odd Enter a number: 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!