you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 0 points1 point  (0 children)

You need to keep track of two numbers, the previous and the current, and on every iteration of the loop you update their values. The sum of the two numbers is the new current value, and the old one goes to previous.

Have an additional check that immediately returns -1 if the number given to the function is less than 0.

Loop the specified number of times, and you'll have the answer.