Question: Can you update the code belowby adding functions functions that will print a menu that performs the following functions? The main function is already written.

Can you update the code belowby adding functions functions that will print a menu that performs the following functions?

The main function is already written. Add the following functions to complete the program:

getUserChoice(): This integer function will use cin to get and return the user's menu choice.

findEvenNumbers(): This void function will prompt the user for N and print the even numbers from 0 to N

findOddNumbers(): This void function will prompt the user for N and print the odd numbers from 1 to N.

Sample Output:

What would you like to do?

1. Find even numbers 0 - N

2. Find odd numbers 0 - N

3. Quit program

Enter your choice: 1

Enter N: 16

Even numbers: 0 2 4 6 8 10 12 14 16

What would you like to do?

1. Find even numbers 0 - N

2. Find odd numbers 0 - N

3. Quit program

Enter your choice: 0

ERROR: Invalid choice. Select a valid menu item.

What would you like to do?

1. Find even numbers 0 - N

2. Find odd numbers 0 - N

3. Quit program

Enter your choice: 2

Enter N: 6

Odd numbers: 1 3 5

What would you like to do?

1. Find even numbers 0 - N

2. Find odd numbers 0 - N

3. Quit program

Enter your choice: 3

Terminating program...

CODE:

//Description: this program will print a sequence of even and odd numbers

#include

#include

#include

using namespace std;

// Function prototypes:

int getUserChoice();

void findEvenNumbers();

void findOddNumbers();

int main()

{

int user_choice;

do{

cout << endl

<< "What would you like to do?" << endl

<< "1. Find even numbers 0 - N" << endl

<< "2. Find odd numbers 0 - N" << endl

<< "3. Quit program" << endl << endl;

cout << "Enter your choice: ";

user_choice = getUserChoice(); // Function call

switch(user_choice)

{

case 1:

findEvenNumbers(); // Function call

break;

case 2:

findOddNumbers(); // Function call

break;

case 3:

cout << "Terminating program..." << endl;

break;

default:

cout << "ERROR: Invalid choice. Select a valid menu item."

<< endl << endl;

}

}while( user_choice != 3 );

return 0;

}

// Function definitions:

// ADD CODE HERE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Lets complete the program by adding the required functions We will add three functions getUserChoice ... View full answer

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 Programming Questions!