Running total
Inputs
n is a whole number from 0 to 100.
Your tasks
- Create a number
totalthat starts at 0. - Use a loop to add each whole number from 1 up to and including
ntototal. - Complete
sumToNso it returnstotal. Return it, do not print it.
Example
With n = 4, sumToN returns 10.
Rules
- If
nis 0, return 0.
Test data
TEST DATA 1: n is 4
TEST DATA 2: n is 0
Practice focus
Loops that count, add up and multiply. Every algorithm starts here: a counter, a total and a stopping point.