At this time, you need to create menu driven program. The menu includes the following list. The menu should keep showing if a wrong choice is selected until one of the choices of 1 to 4 is selected. After each of the options 1 to 3 is done, the program shows the menu and waits for the user's choice.
Upload your code here.
1. Add odd numbers from a to b
2. Add even numbers from a to b
3. Show multiples of c from a to b
4. Exit
If you have any doubts, please give me comment...
import java.util.Scanner;
public class Exercise{
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int choice=1, a=0, b=0, c=0;
do{
System.out.println("MENU");
System.out.println("1. Add odd numbers from a to b");
System.out.println("2. Add even numbers from a to b");
System.out.println("3. Show multiples of c from a to b");
System.out.println("4. Exit");
System.out.print("Your choice: ");
choice = scnr.nextInt();
if(choice==1 || choice==2 || choice==3){
System.out.print("Enter a: ");
a = scnr.nextInt();
System.out.print("Enter b: ");
b = scnr.nextInt();
}
switch(choice){
case 1:
{
int sum = 0;
for(int i=a; i<=b; i++){
if(i%2==1)
sum += i;
}
System.out.println("Sum is: "+sum);
}
break;
case 2:
{
int sum = 0;
for(int i=a; i<=b; i++){
if(i%2==0)
sum += i;
}
System.out.println("Sum is: "+sum);
}
break;
case 3:
{
System.out.print("Enter c: ");
c = scnr.nextInt();
System.out.print("Multiples of "+c+" is:");
for(int i=a; i<=b; i++){
if(i%c==0)
System.out.print(" "+i);
}
}
break;
case 4:
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid Choice! Try again...");
break;
}
System.out.println();
}while(choice!=4);
}
}
At this time, you need to create menu driven program. The menu includes the following list....
Write a menu driven program to demonstrate the use of array and switch. It must be written in C language . Here is the menu - Press 1 to add a number to the array. Press 2 to display the numbers entered in the array so far Press 3 to find the average of the numbers entered. Press 4 to exit. Option 1 - The user should be able to enter 20 numbers only. If all twenty numbers are entered...
Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...
Please design, write the code and create the requisite submission files in C++ for the following problem: A menu-driven program that offers the user 5 options as follows: Menu: 1. Display array 2. Add up all elements in the array and display that number. 3. Add 1 to each element in the array. 4. Swap the values in row one with the values in row three. 5. Exit In main(), declare and initialize a 2-dimensional array that contains 5 x...
***C++ Program ONLY*** Menu driven program First load an array(lists) with the values 3, 4, 84, 5, 2, 47, and 7 in this order Then sort the array(list) Create a program with a menu, with choices 1 for factorial (single value, which everyone will use 20!), 2 for median value , 3 for average, 4 for maximum, 5 for minimum, and 6 to end the program. Use a do loop (not while) Python does not have a Do loop, so...
extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...
Design program so that it correctly meets the program specifications given below. Specifications: Create a menu-driven program that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- square 2 -- circle 3 -- right triangle 4 -- quit If the user selects choice 1, the program should find the area of a square. If the user selects choice 2, the program should find the area of a circle. If the user...
***C++ ONLY*** Menu driven program First load an array(lists) with the values 3, 4, 84, 5, 2, 47, and 7 in this order Then sort the array(list) Create a program with a menu, with choices 1 for factorial (single value, which everyone will use 20!), 2 for median value , 3 for average, 4 for maximum, 5 for minimum, and 6 to end the program. Use a do loop (not while) Python does not have a Do loop, so instead...
In C++ write a simple menu program that displays a menu for the user in an object-oriented technique. The menu should keep showing up until the user chooses to quit. Also, there is a sub-menu inside a menu. The user should get at least a line displayed after he or she chooses that particular option meaning if the user presses 1 for the read actors from the file. The output can look like "reading actors from a file" and then...
Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...
Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...