Lab 4

2010_F18/wk4/lab4.cpp

The purpose of this lab is to create a menu based program within a do while loop to practice the concepts of looping control structures, counter variables, sentinel values, and running totals. The program will have three choices: 1. Part A, 2. Part B, and 0. Exit.

Part A

Calculate a running total of positive integer values using a while loop and a boolean flag that will test for the condition of a sentinel value. You will use the concept of a running total and sum up a series of inputed values together until the sentinel value of (-1) is entered. Validate that each inputed value is positive, otherwise have the user re-enter a positive value until valid. Once the sentinel value is entered, you will output the max, min, and average with percision up to 2 decimal places (remember not to inlcude the sentinel value (-1) as an inputed value with your calculations). You will need to use the iomanip library for decimal percision. You will also need a counter variable to count the number of values inputed.

Part B

Calculate the factorial of  n!  Prompt the user for a positive number, validate, then assign the inputted value to n. Using a for loop, calculate the factorial, then output the result. For example: if the user enters 4, the program will output "4! = 1x2x3x4 = 24".

Part A example:

Please enter an integer: 1 [entered]
Please enter an integer: 2 [entered]
Please enter an integer: 3 [entered]
Please enter an integer: -1[entered]

Min: 1
Max: 3
Total: 6
Avg: 2.00

Part B example:

Please enter a value for n!: 4 [entered]
4! = 1x2x3x4 = 24