Question
1. Your task is to write a C++ program which makes three different computations, each controlled by some loop. You will prompt the user for
1. Your task is to write a C++ program which makes three different computations, each controlled by some loop. You will prompt the user for loop intervals something like you did for the last program.
(a) Your program will first prompt the user for one integer. It will then compute the sum of the values between 1 and the users input value. That is it will compute Xn i=1
This phase of the program shall use a for loop for the computation.
If the users input is less than 1, you will continue to prompt the user for a value greater than or equal to one, until the user complies.
When the computation is done, output the result in a single line like The sum of integers from 1 to 5 is: 15
(b) Next, you will prompt the user for a pair of integers and output the length of the interval between the numbers. Example: if the input is 5 5 the length is 0, if the input is 5 6 the length is 0, if the input is 1 9 the length is 7. Notice that the endpoints are NOT counted in the length.
This time you shall use a while loop to determine the interval.
There are no incorrect values here, any two integers will do.
When the computation is done, output the result on another line like The interval between 1 and 5 is: 3
Yes, I know there are easier ways to do this than using a while loop, but this is for practice with loops.
(c) Last you will compute the product ni. Prompt the user for two more integers and make the computation. YOU WILL NOT USE ANY SPECIAL FUNCTIONS TO MAKE THIS COMPUTATION!!!!
Now you shall use a do-while loop.
The first value input, n can be any integer. The second value, i, must be a non-negative integer. If the I input is negative, you will continue to prompt the user for a new pair of values, n and i, where the i is non-negative. Note: If the input values are large, the result will overflow and what is printed out will really be garbage. That is the way things happen sometimes, do not worry about it. Certainly, do NOT try to detect this issue in the program.
When the computation is done, output the product on a third line like The product of 3 4 is: 81
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