Question: Question 4 (a) Develop a program that performs the following task 5 times using only the for-loop flow control structure to write: obtain an integer

Question 4 (a) Develop a program that performs the following task 5 times using only the for-loop flow control structure to write: obtain an integer value from the user, calculate the average of all integers entered so far, and display the average. Below is an example of the input and output of the program with some explanations. Average = 1/1 Enter an integer: 1 Average so far: 1 Enter an integer: 2 Average so far: 1.5 Enter an integer: 3 Average so far: 2 Average = (1 + 2)/2 = 1.5 Average = (1 + 2 + 3)/3 = 2 (10 marks) (b) Given the system info provided in Table Q4(b), develop a program that repeatedly performs the following tasks: i Prompt the user for a choice, and upper limit integer ii. Display the function name of that choice, and the upper limit entered by the user iii Display the sequence of numbers based on the choice and upper limit (odd or even sequence) iv. Terminate the program if the user entered an invalid choice Note: you may up any combination of the while, do-while, if-else, if, and/or switch flow control structures. Hint: Use a while or do-while loop structure to repeat the entire program, a switch or if-else structure to perform task ii, and a for or while loop to perform task iii. Table 4(b) choice Function name Example Sequence with limit = 7 1 Odd Numbers 1 3 5 7 2 Even Numbers 0 2 4 6 (10 marks) (Total: 20 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
