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

This is a discussion on Help writing program that asks user for number and prints sum of all numbers between within the C Programming forums, part of the General Programming Boards category; Hello, I've been given a problem where I need to ask the user to input a number between 1 and ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    17

    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. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,625
    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.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    17
    Quote Originally Posted by tabstop View Post
    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. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    17
    Quote Originally Posted by grumpy View Post
    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. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you not see the thread in this very forum about "adding numbers from 1 to 1,000,000"?

  7. #7
    Registered User
    Join Date
    Dec 2010
    Posts
    17
    Quote Originally Posted by tabstop View Post
    Do you not see the thread in this very forum about "adding numbers from 1 to 1,000,000"?
    And how does that help me? Instead of pointing me to other threads, can you please help me with the actual code?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by celticpride View Post
    And how does that help me? Instead of pointing me to other threads, can you please help me with the actual code?
    That thread provides a (worked-out!) example of the type of thing that you are (supposed to be) doing. Therefore, we point you to that thread, so that you can read it and see an example of what it is you need to be doing. I realize that not lovingly hand-crafting code for you to use does not make you feel like a special and unique snowflake. But them's the breaks.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by celticpride View Post
    And how does that help me? Instead of pointing me to other threads, can you please help me with the actual code?
    Ummm no... it's you that has to write the code.

    Check this board's homework policy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program the prints prime numbers
    By cloudstrife910 in forum C++ Programming
    Replies: 8
    Last Post: 09-22-2010, 04:03 PM
  2. Replies: 12
    Last Post: 02-28-2008, 06:19 PM
  3. Program that prints numbers in columns
    By rayrayj52 in forum C++ Programming
    Replies: 12
    Last Post: 09-20-2004, 03:43 PM
  4. Enistine program
    By Mac_the vamp in forum C Programming
    Replies: 2
    Last Post: 11-11-2002, 10:56 AM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21