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.
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.
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
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.
This is what the program looked like:
#WSQ07 – Sum of Numbers by kevingmcc is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.