0

I do not have any code to provide, mainly because my teacher is not good so I have no clue where to start. But for example if you chose 3 and 20 then it would add up 3, 7, 11, 15, 19 to display the sum of 55. What would be the basis of writing this code? What would be the language you would use? Please give an example of how to do it. It would be greatly appreciated.

1 Answers1

0

Using your example:

You need a variable that holds the total sum which initially will be zero, another one to keep track of the current number, and another one to know if you are on a 4th number.

You need a loop that starts in 3 and finishes on 20, and you need to track the current number with one of the already mentioned variables.

In the loop you will go incrementing the current value, and also the variable to know if your are on a 4th number (if it starts in 1, when it reaches 4, you are on a 4th number).

Every time you are on a 4th number, you will have to add the current value to the total sum, and reset the 4th number count to knwo when you reach the next one.

I hope this helps you with your homework.

Juan
  • 5,525
  • 2
  • 15
  • 26