Question

In: Computer Science

Create a command based menu using functions. The structure should be as followed: Under the main...

Create a command based menu using functions.

The structure should be as followed:

  • Under the main menu
    • Submenu1
    • Submenu2
    • Exit
  • SubMenu1
    • Choice1
    • Choice2
    • Back to main menu
  • Submenu2
    • Choice1
    • Choice2
    • Back to main menu
  • When I am in the submenus I want to know when I press a an option.
    • Example:
      • You have chosen choice 2 in submenu1
      • You have chosen choice 1 in submenu2
  • If an option is chosen that is incorrect I want the output to say so
    • Example:
    • "Error: you didn't choose a valid option"
  • It needs to be saved as a .PS1 file and submitted

Solutions

Expert Solution

C Program to implement submenu's using functions:

#include <stdio.h>
#include <stdlib.h>

//Sub Menu 1
void SubMenu1()
{
printf("\n ***** Sub Menu 1 ***** \n");
printf(" 1 - Choice 1 \n");
printf(" 2 - Choice 2 \n");
printf(" 3 - Back to Main Menu \n");
}

//Sub Menu 2
void SubMenu2()
{
printf("\n ***** Sub Menu 2 ***** \n");
printf(" 1 - Choice 1 \n");
printf(" 2 - Choice 2 \n");
printf(" 3 - Back to Main Menu \n");
}

//Main Menu
void MainMenu()
{
printf("\n ***** Main Menu ***** \n");
printf(" 1 - Submenu 1 \n");
printf(" 2 - Submenu 2 \n");
printf(" 3 - Exit \n");
}

int main()
{
int opt=0, opt1=0, opt2=0;

//Loop till user quit
while(opt != 3)
{
//Displaying main menu
MainMenu();
printf("\n\nYour Choice: ");
//Reading choice
scanf("%d", &opt);

//Switch
switch(opt)
{
case 1:
//Sub Menu 1
while(opt1 != 3)
{
//Printing sub menu 1
SubMenu1();
printf("\n\nYour Choice: ");
//Reading choice
scanf("%d", &opt1);

if(opt1 == 3)
break;

switch(opt1)
{
case 1: printf("\n You have chosen choice 1 in submenu1 \n"); break;
case 2: printf("\n You have chosen choice 2 in submenu1 \n"); break;
default: printf("\nError: you didn't choose a valid option\n");
}
}
break;

case 2:
//Sub Menu 2
while(opt2 != 3)
{
//Printing sub menu 2
SubMenu2();
printf("\n\nYour Choice: ");
//Reading choice
scanf("%d", &opt2);

if(opt2 == 3)
break;

switch(opt2)
{
case 1: printf("\n You have chosen choice 1 in submenu2 \n"); break;
case 2: printf("\n You have chosen choice 2 in submenu2 \n"); break;
default: printf("\nError: you didn't choose a valid option\n");
}
}
break;

case 3: return;

default: printf("\nError: you didn't choose a valid option\n");
}
}
}

_________________________________________________________________________________________________

Sample Run:


Related Solutions

Please C++ create a program that will do one of two functions using a menu, like...
Please C++ create a program that will do one of two functions using a menu, like so: 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 1 Enter Catalan number to calculate: 3 Catalan number at 3 is 5 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 2 Enter Fibonacci number to calculate: 6 Fibonacci number 6 is 8 Create a function of catalan that will take a parameter and return...
AutoCAD command prompts are grouped under Tabs according to their command functions. Such groups are labelled...
AutoCAD command prompts are grouped under Tabs according to their command functions. Such groups are labelled as PANELS. Explore into details FIVE panels.   
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
C++ Write a menu based program for the pet rescue. There should be 2 menu options...
C++ Write a menu based program for the pet rescue. There should be 2 menu options -Add a pet -View pets -If the user chooses option 1, you will open a data file for writing without erasing the current contents, and write a new pet record to it. The file can be formatted any way that you choose but should include the pet's name, species, breed, and color. You my also include any additional information you think is appropriate. -If...
Using C++ 1. Create a main function in a main.cpp file. The main function should look...
Using C++ 1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;} 2. Create an array. 3. Ask user to enter numbers in size of your array. 4. Take the numbers and store them in your array. 5. Go through your array and add all the numbers. 6. Calculate the average of the numbers. 7. Display the numbers, sum and average.
unix/Linux Create a tar command using the man command and the link referred to in To...
unix/Linux Create a tar command using the man command and the link referred to in To Practice and Explore: Text File Utilities #9. Preliminaries Use the man pages to learn more about tar Review the links referred to in To Practice and Explore: Text File Utilities #9 to see examples of using tar command Perform Use tar "to stuff" three files and then "unstuff" them into a new directory. Include the -v option. Task ll to show the original 3...
CREATE A CASH MANAGEMENT STRUCTURE AND DEFINE EACH OF THE FUNCTIONS AND CREATE SAMPLE CAPITAL STRUCTURE
CREATE A CASH MANAGEMENT STRUCTURE AND DEFINE EACH OF THE FUNCTIONS AND CREATE SAMPLE CAPITAL STRUCTURE
///create a main menu to enter choices such as "Welcome to any college" then please enter...
///create a main menu to enter choices such as "Welcome to any college" then please enter your choice of information when you press a key 1. view students. 2. insert student 3. remove student 4. exit...and student ID#, age, birthday, location, expected gradation date import java.util.Scanner; public class CourseCOM666 { private String courseName; private String [] students = new String[1]; private int numberOfStudents; public CourseCOM666(String courseName) { this.courseName = courseName; } public String[] getStudents(){ return students; } public int getNumberOfStudents(){...
Create a menu-based program that will allow the user to calculate the area for a few...
Create a menu-based program that will allow the user to calculate the area for a few different shapes: square, rectangle, parallelogram, and circle. Refer to the Sample Output in this document to see what menu options you should use. Create PI as a global constant variable. Main Function use do-while to repeat program until user chooses option 5 call the displayMenu function get user choice & validate with while loop depending on user’s choice, get the data required to calculate...
Create a menu-based program that will allow the user to calculate the area for a few...
Create a menu-based program that will allow the user to calculate the area for a few different shapes: square, rectangle, parallelogram, and circle. Refer to the Sample Output in this document to see what menu options you should use. Create PI as a global constant variable. Main Function use do-while to repeat program until user chooses option 5 call the displayMenu function get user choice & validate with while loop depending on user’s choice, get the data required to calculate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT