Question: NEED HELP COMPLETING THIS CODE Write a program that asks the user for a positive integer value between 2 and 100 inclusively. The program should

NEED HELP COMPLETING THIS CODE

NEED HELP COMPLETING THIS CODE Write a program that asks the user

for a positive integer value between 2 and 100 inclusively. The program

Write a program that asks the user for a positive integer value between 2 and 100 inclusively. The program should use a while loop to compute the sum of all integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4, 50 and after the loop terminates, output the message, "Sum of numbers 1 + 2 + ... + 50 is 1275". If the user enters an integer less than 2 or an integer greater than 100, the program should give the error message, "Invalid entry. Integer should be between 2 and 100." and then terminate. Hint You will need a counter and an accumulator. If needed, reference slide 2 of Lect5a_Part2_while_cont.pptx. Create a limit variable, take the input from user and populate it, and then use it in the while loop in place of 10. When the input as is shown in Figures 1 & 3. your program should produce the output as shown in Figures 2 & 4. Figure 1 (sample input) 50 Figure 2 (sample output) Sum of numbers 1 + 2 + + 50 is 1275 Figure 3: (sample input) 2 Figure 4: (sample output) Sum of numbers 1 + 2 is 3 286488-1697196 5 #include 6 using namespace std; 7 int main 10 7/ define variable define an accumulator variable and initialize it to o V/ define a limit variable to be input by the user // define a counter variable and initialize it to 1 12 13 15 16 read in the limit Jivalidate the limit is between 2 and 100 inclusievly if() // the limit is invalid, output 18 ( 2e } 21 else // limit is valid so sum the numbers from 1 to limit 22 23 while() //use a while loop to sum the numbers from 1 to limit 24 25 I add the counter variable to the sum variables 26 Il increment the counter variable 27 28 I use an if statement to test if limit is 2 and if so, 29 // output data in format: sum of numbers 1 + 2 is 3 30 Helse 31 //output data in format: sum of numbers 1 + 2 + ... + limit is sum 32 return; 34

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!