Question
3. Your task is to write a C++ program which performs one of three operations based on the input values. Once again we will only
3. Your task is to write a C++ program which performs one of three operations based on the input values. Once again we will only input integers. All of the inputs will be non-negative. This program will run in a loop, asking the user for values, making computations, printing results, until the user inputs the sentinel value of -9999.
(a) Your program will prompt the user for a non-negative integer.
This prompt and input MUST be done with a function.
If the user inputs a negative value that is not the sentinel value you will display the prompt again and read another value until either a non-negative value is input or the sentinel value is input.
This function will have no arguments (void).
It will return an integer.
Its prototype is exactly int myPrompt( void );
The return value will be either a non-negative integer or the sentinel value.
(b) If the user inputs a value from 10 to 45 (inclusive), then you will compute the sum of the numbers between 1 and the input value.
This computation MUST be done with a function.
This function will take as an argument a single integer.
It will return an integer.
Its prototype is exactly int mySum( int );
(c) If the user inputs a non-negative value less than 10, then you will compute product of the values between 1 and the number. This is a factorial (n!). By definition 0! is 1, 1! is 1 0!, 2! is 2 1!, etc.
This computation MUST be done with a function.
This function will take as an argument a single integer.
It will return an integer.
Its prototype is exactly int myFact( int );
(d) If the user inputs a value greater than 45, then you will compute the remainder of that value divided by 13.
This computation MUST be done with a function
This function will take as an argument a single integer
It will return an integer.
Its prototype is exactly int myMod( int );
(e) Once you have made a computation, you will print the result. This print out will be one of
1. The sum from 1 to 13 is 91
2. The product from 1 to 7 is 5040
3. The remainder of 68 / 13 is 3
This output MUST be all generated by a single print function.
This function will take as arguments two integers.
It will return void.
Its prototype is exactly void myPrint( int, int );
(f) All of the function prototypes will be before main().
(g) There will be NO global variables. All the information the functions need or supply will be in their arguments or return values.
(h) All of the function definitions will occur after main().
(i) Use stubs. You are STRONGLY advised to do so.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started