Back to Challenge Set 9

Code Challenge: Add It Up

Difficulty  

divider

The Brief

What they asked for
I want to know the sum of every whole number from 1 up to
whatever number I give you, without doing the addition
myself.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • The number of passes is exactly the number typed in. That is a for, the same shape as Times Table in this set.
  • This one keeps a running total across every pass, which Times Table did not need. The total has to exist before the loop starts, at 0.
  • “Up to whatever number I give you” means that number is included. Check your loop's condition against that.
  • Print the total once, after the loop ends — not once per pass.

Where to Start

Only one-star challenges have this section. If you already know how to begin, skip it — and when you move up to two stars, working out the order yourself is part of the job.

  1. Read the number and parse it with int.Parse.
  2. Declare a total, starting at 0, before the loop.
  3. Write a for loop from 1 up to and including that number, adding each pass's value to the total.
  4. Print the total after the loop. Test with 10 — you know the answer is 55.

Sample Output

Sample Output
Add up to what number? 10
Sum: 55

Verified in a real run — 1 through 10 sums to exactly 55.


Submit

Your requirements list and your program file, named cc-add-it-up.

Commence Challenge