NUMB3R5

Picture by energepic.com energepic.com

For WSQ04 you may want to get prepared and to know several things first, things like:

  • Reading chapter 4 of our book to learn how to do conditionals.
  • This other page may work too.
  • Other help to actually do this WSQ.
  • Optional: if you want to know the actual formula or maybe get dome extra information this may help.

Captura de pantalla 2017-01-31 a la(s) 13.31.53.png

Al right so let’s get started, as you can see from the picture above first we have to declare variables and give the initial structure, which is asking for the values, then you will need to do an if else condition, if n1 (which is the lower number), is bigger than n2 (upper number) then we do what the program is expected to do, to sum the values between the two integer given. For this process we have to use the for condition (well you don’t have to, there are other ways, but I’ll show you to do it this way), what you put in the parenthesis:

  1. Declare the variable for the for condition, I used x and I said that it’s the same as the lower value.
  2. The next thing is that while x (lower number) is less or the same as our higher value, we will continue to do this process.
  3. The process which is adding one to our lower value, that’s what it means by x++, its the same if you put x=x+1.
  4. Finally we print the result as ans, that why I put ans+=x; that means the same as ans=ans+x.

At this point we finished the hardest part of our program, but now comes the other part of the if, the else, here is the option that the user may give us the lower value as the highest one and viceversa. What I did here is copying the same of our first part but changing the values, I mean the n1 for n2 and so on. I gave the explanation of what I did in my program.

As always my program at GitHub.

Here is a screenshot of my program in both cases, the first one is when the user gives the correct values and the second one is when the user gives the values in the wrong order.

1)

Captura de pantalla 2017-01-31 a la(s) 14.24.25.png

2)Captura de pantalla 2017-01-31 a la(s) 14.25.02.png

If you have any questions feel free to ask, and as always, thanks for reading the post.

 

L.out

Deja un comentario