Question 2) Write a user defined function called AdvancedMenu that simulates a menu with options the user can select. The function takes no arguments and does not return anything. The menu has the following options. 1. Blue Button Pressed 2. Green Button Pressed 3. Red Button Pressed 4. Yellow Button Pressed 5. Exit The user will select one of the four options and the program will display the option selected. If the user selects options 1-4, the program will ask the user to enter another option. If the user selects option 5, the program will not loop again. Hint: Use the switch statement and while loop.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Q in picture

**C PROGRAMMING LANGUAGE

***PROVIDE COMMENTS

Question 2) Write a user defined function called AdvancedMenu that simulates a menu with
options the user can select. The function takes no arguments and does not return anything. The
menu has the following options.
1. Blue Button Pressed
2. Green Button Pressed
3. Red Button Pressed
4. Yellow Button Pressed
5. Exit
The user will select one of the four options and the program will display the option selected. If
the user selects options 1-4, the program will ask the user to enter another option. If the user
selects option 5, the program will not loop again. Hint: Use the switch statement and while loop.
Transcribed Image Text:Question 2) Write a user defined function called AdvancedMenu that simulates a menu with options the user can select. The function takes no arguments and does not return anything. The menu has the following options. 1. Blue Button Pressed 2. Green Button Pressed 3. Red Button Pressed 4. Yellow Button Pressed 5. Exit The user will select one of the four options and the program will display the option selected. If the user selects options 1-4, the program will ask the user to enter another option. If the user selects option 5, the program will not loop again. Hint: Use the switch statement and while loop.
Expert Solution
Step 1

For defining a function we have to look at the syntax of the function, and other syntax used in the code to solve the problem in the c language.

function declration:

syntax:

return_type function_name(parameter list separate by comma);

The parameter list is optional

calling function:

To run a particular function we have to call it.

syntax:

function_name(parameter list separated by comma);

The parameter list is depending on your declared function's parameter list.

initializing function:

To initializing function just write code in the curly braces 
syntax:

return_type function_name(parameter list separated by comma){

 // write your code

}

Note: we can initialize the function at declaring time also.

 

While loop:

Syntax:

while(condition){

// statement

}

It will execute its body's statement until the condition will not give a false result.

 

Switch statement:

Syntax:

switch(input){
            case 1:
                Statement block 1;
                break;
            case 2:
                Statement block 2;
                break;
            default:
                Statement block 3; 
                break;

}

The switch is checking the matching value of the variable to the case and if it matches then execute that case statement block if the case value and variable value will not match then execute the default case's statement block.

 

Printing statement:

To printing a statement, we can use printf() method.

Syntax:

printf("statement");

 

Reading a value from user:

To reading data from users, we can use scanf() method.

Syntax:

scanf("%data_type_character", &variable_name);

 

 

 

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education