Question

In: Computer Science

Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End...

Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End Program.The user can only input a positive integer (0 does not count) and if the input is not a positive integer the program must state "Invalid Input." The program must determine whether the input is even or odd. The program must use functions and can only use the iostream and iomanip libraries.

Note: The program must loop until the 2nd menu option is chosen.

Solutions

Expert Solution

Code:

#include <iostream>

using namespace std;

int main() {

int option;

do{

cout<<"1)Is it odd or even?\n2)End Program."<<endl;

cin>>option;

switch(option){

case 1:

int n;

cout<<":";

cin>>n;

if(n<0){

cout<<"Invalid Input"<<endl;

}else{

if(n%2==0){

cout<<"Even"<<endl;

}else{

cout<<"Odd"<<endl;

}

}

break;

case 2:

break;

default:

cout<<"Choose from menu"<<endl;

}

}while(option!=2);

return 0;

}

Snapshot for indentation:

Sample run:


Related Solutions

Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
Write a menu program to have the above options for the polynomials. Your menu program should...
Write a menu program to have the above options for the polynomials. Your menu program should not use global data; data should be allowed to be read in and stored dynamically. Test your output with the data below. Poly #1: {{2, 1/1}, {1, 3/4}, {0, 5/12}} Poly #2: {{4, 1/1}, {2, -3/7}, {1, 4/9}, {0, 2/11}} provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1....
This is an exercise for a menu-driven program. Program should use shell functions. Write a program...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a rectangle 3. Calculate the area of a triangle 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ?...
Write a menu-driven program to handle the flow of widgets into and out of a warehouse....
Write a menu-driven program to handle the flow of widgets into and out of a warehouse.     The warehouse will have numerous deliveries of new widgets and orders for widgets     The widgets in a filled order are billed at a profit of 50 percent over their cost     Each delivery of new widgets may have a different cost associated with it     The accountants for the firm have instituted a last-in, first-out system for filling orders         the newest...
Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program...
Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program should allow the user to select one of the options according to whether lengths, weights or volume are to be converted, read the volue to be converted and the units, and then call the appropriate function to carry out the conversion In unit out unit I C (inch to centimeter 1 in = 2.4 cm) F C (feet to centimeter 1 ft = 30.4...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java program that will solve the following problem. The program uses one and two-dimensional arrays to accomplish the tasks specified below. The menu is shown below. Please build a control panel as follows: (Note: the first letter is shown as bold for emphasis and you do not have to make them bold in your program.) Help SetParams FillArray DisplayResults Quit Upon program execution, the screen...
Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish...
In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish and Spanish to English. Your translation program should use arrays for this program. You will need to populate the arrays with the contents of the English and Spanish data files provided. The two files are ordered such that each word in the one file corresponds to the respective translation in the other (i.e.: the first word in the ENG.txt file corresponds to the first...
C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of...
C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of tasks relating to student marks scored in a number of assessments including: displaying all marks, adding new student marks, calculating the mean score, median score, finding the minimum and maximum scores as well as displaying the average mark of a given student. The problem: Student marks are kept in a text file as a single column. Each student may have a different number of...
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The...
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The function will have one int 1D array n and one int size as parameters. The function will display all the values of n on one line. Function #2 Write the function AverageEvenOdd. The function will have one int 1D array n and one int size as parameters. The size of the array is given by the parameter int size. Therefore, the function should work...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT