Question: You are to write a single c program that displays a simple menu with a few menu items. Each menu item is associated with a
You are to write a single c program that displays a simple menu with a few menu items. Each menu item is associated with a C function that performs a certain process as elaborated below. ACTION LIST MENU ---------------- 1. Compute factorial of n 2. Compute SumSquare of n 3. Compute SumOdd of n 4. Exit Hint: the structure for this C program is as follows int main() { menuController(); return 0; } List of function: GetNumber This function prompts the user to input an integer number between 1 and 10 and returns a valid entry. It is obvious that this function validates the input before returning the control to its invoker. DisplayMenu This function displays the menu of the possible actions as follows MenuController This function invokes functions GetNumber and then DisplayMenu. Based on the user selection, it invokes the corresponding function to perform the task. This process will be performed repeatedly until the user chooses to exit. Hint: the process of task allocation will be implemented using a switch statement based on the choice made by the user. ComputeFactorial This is a non-recursive function that accepts an integer n as input parameter and computes and returns n! Hint: n!= n*(n-1)*(n-2)*1 Example: 5!=5*4*3*2*1=120
SumSquare This function accepts an integer n as input and computes and returns the total of all numbers raised to the power of two (squared) within the range of 1..n (including n itself) Example: SumSquare(5)= 1 2+2 2 + 3 2 + 4 2 + 5 2=1+4+9+16+25=55 SumOdd This function accepts an integer n as input and computes and returns the total of all odd numbers within the range of 1..n (including n itself if n is odd) Example: SumOdd(5)=1+3+5=9 PrintOutput This is a void function that accepts an integer as input parameter and is responsible for printing any output of the program. Sample output of the program: Please enter an integer between 1 and 10: 11 You have entered an invalid entry! Please enter an integer between 1 and 10: 6 ACTION LIST MENU ---------------- 1. Compute Factorial of n (n!) 2. Compute SumSquare of n 3. Compute SumOdd of n 4. Exit Please select one action from the above list? 5 Your entry was invalid! Please select one action from the above list? 1 The factorial of 6 (6!) = 720 Please select one action from the above list? 2 The sum square of 6 = 91 Please select one action from the above list? 3 The total of odd numbers between 1 and 6 = 9 Please select one action from the above list? 4 Goodbye!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
