Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone please help me solve my problem in a similar way i'm coding. this is the 2nd time i'm posting this because the last

image text in transcribed

image text in transcribed

can someone please help me solve my problem in a similar way i'm coding.

this is the 2nd time i'm posting this because the last answer made no sense to me

image text in transcribed

this is what the last person said and when i ran it it was incorrect i dont know what "lt" is please solve mine in a similar way to as i typed my program i'm still learning and am not an expert i don't know any other way other than the way i've been taught please keep it simple and help me. !!!

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, your output should actually include the ++ and not the actual numbers) Sum of numbers 1+2++50 is 1275 Figure 3: (sample input) 2 Figure 4: (sample output) 345678910111213141516171819202122232425262728//Lab28#includeusingnamespacestd;intmain(){//definevariablesintsum,num;//defineaccumulatorvariableandinitializeitto0intsum=0//definealimitvariabletobeinputbutusercin>>num;//readinthelimit//validatethelimitisbetween2and100inclusivelyif0return0; The code you have posted is incomplete. You need to define the variable n and assigr it a value. You also need to set the initial value of i to 0. \#include \ using namespace std; int main() \{ int i=0; int n; // define n int limit; int sum =0; cout \\> limit; n= limit; // assign a value to n for (i =0; i \ This code will find the sum of all numbers from 1 to the limit provided by the user. It starts the loop with i code > set to 0 and stops when i code > is greater than or equal to the limit entered by the user. It then prints out the sum of all the numbers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. The purpose of the acquisition of the information.

Answered: 1 week ago