Page 1 of 1

Program Specifications • Carefully read the entire Program Specification before beginning. • FOLLOW THE SPECIFICATIONS B

Posted: Tue Jul 12, 2022 8:15 am
by answerhappygod
Program Specifications Carefully Read The Entire Program Specification Before Beginning Follow The Specifications B 1
Program Specifications Carefully Read The Entire Program Specification Before Beginning Follow The Specifications B 1 (117.44 KiB) Viewed 36 times
Program Specifications • Carefully read the entire Program Specification before beginning. • FOLLOW THE SPECIFICATIONS BELOW TO create the following functions to calculate and display the sum or product of the integers from 1 to the number input. • getNum • Receives no input. Prompts the user to enter an integer. Uses a loop to validate. Insures that no number, entered, is negative or zero. Returns the result. • calcSum Receives an integer as input. USE AN ACCUMULATOR to calculate the sum of the integers from 1 to this number. Returns the result. • calcProd · Receives an integer as input. USE AN ACCUMULATOR to calculate the product of the integers from 1 to this number. Returns the result.
Program Specifications • Main should: • Prompt for a character that determines if you want to calculate the sum ('S' or 's') or product ('P' or 'p'). If a valid option is entered, use getNum to prompt for the number • Note that calcSum and calcProduct RETURN the result to main, and the output is printed in main. • For example, if you input 5 as the number, and 'S', the program should calculate 1+ 2+ 3+ 4+ 5 and display the sum as 15. If you input 5 and 'P' the program should calculate 1 x 2 x 3 x 4 x 5 and display the product as 120. • The process should repeat as long as the user wants to continue. This loop should be in main.