Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Are we managing our human capital as a strategic asset?

Answered: 1 week ago