#WSQ07 – Sum of Numbers

In this problem I had to ask the user to give me to numbers and give him the sum of the range of all numbers between the two numbers given.

The first thing I did was tell the user a brief instructive on what this program will do.

The I asked for the first number, which will be the lower bound, followed by asking the second number, which will be the upper bound.

Screen Shot 2016-02-20 at 4.45.17 PM

Next I created a variable  called ‘suma’ that will hold the value of all of the sums that the the program makes until getting to the upper bound number the user gave. Also I created another variable called ‘candidate’ which will hold the value of the lower bound number for purposes of using it in the for loop.

Screen Shot 2016-02-20 at 7.24.03 PM

Then I created a for loop and set the assignment to takes the ‘candidate’ value and I used the keyword ‘range’ and set it the parameters to be the (firstNum and secondNum+1) in order for the second number to be inclusive.

Inside the loop I set the value of suma = suma + candidate

Screen Shot 2016-02-20 at 7.29.29 PM

Finally I printed a message that lets the user know the first number he chose and the last one followed by the result of the numbers in their range including both of the numbers he chose.

Screen Shot 2016-02-20 at 7.32.20 PM

This is what the program looked like:

Screen Shot 2016-02-20 at 7.32.58 PM

CC BY-SA 4.0 #WSQ07 – Sum of Numbers by kevingmcc is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.