What to Do
Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).
You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.
For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.
Notice our sum starts with zero (why?) and then we add each number in the range provided by the user. Just for fun, what is the mathematical formula to do this calculation?
We will calculate the sum of integers in the range you provide.
Please give us the lower bound: 1
Please give us the upper bound: 10
The sum from 1 to 10 (inclusive) is: 55
How would you change your program to handle the user giving you the upper and lower bound in the wrong order? Or perhaps some other “user input error”?
What to Submit
As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag WSQ07 on your post so our blog hub picks that up.
You should include your code either inline in the blog post (best option) and/or a link to your actual code on Dropbox/Google Drive/GitHub.
You may want to check how to get started on GitHub now, here is a good article to start with: http://readwrite.com/2013/09/30/understanding-github-a-journey-for-beginners-part-1
And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1014 so we all see your question posted there.
WSQ07 – Sum of Numbers by Ken Bauer is licensed under a Creative Commons Attribution 4.0 International License.