# Thread: Help writing program that asks user for number and prints sum of all numbers between

1. ## Help writing program that asks user for number and prints sum of all numbers between

Hello, I've been given a problem where I need to ask the user to input a number between 1 and 100. The program should then take that number and display the sum of all the numbers between the number the user entered and 1. The actual problem is below:

Write a program that asks the user for a number between 1 and 100 from the user and will print the sum of all the numbers between 1 and that number. For example if the user enters 6 the output should be : The sum of numbers between 1 and 6 is 21.
However, I have no idea where to start coding this.

Any ideas? Thanks.

2. 1. Ask the user for a number
2. Determine the sum of 1+2+3+...+user's number. (Hmmm, a repetitive computation; if only there was some way to repeatedly execute an instruction, or set of instructions, over and over again....)
3. Print the result statement.

3. Hmmm .... there was also a thread in the last few days with a very similar problem.

In this particular case, there is a simple formula that allows the result to be computed without a loop.

4. Originally Posted by tabstop
1. Ask the user for a number
2. Determine the sum of 1+2+3+...+user's number. (Hmmm, a repetitive computation; if only there was some way to repeatedly execute an instruction, or set of instructions, over and over again....)
3. Print the result statement.
I can do the first and third easily, just not the 2nd step.

5. Originally Posted by grumpy
Hmmm .... there was also a thread in the last few days with a very similar problem.

In this particular case, there is a simple formula that allows the result to be computed without a loop.
Could you put me in the right direction?

6. Do you not see the thread in this very forum about "adding numbers from 1 to 1,000,000"?

7. Originally Posted by tabstop
Do you not see the thread in this very forum about "adding numbers from 1 to 1,000,000"?