0

How does the output give 45 and not 10?

Hey everyone, I’m still learning c++ using the book c++ primer, the assignment is to check if the code is valid and what the outputs would be. I’m wondering how sum ends up being 45 instead of 10. https://code.sololearn.com/c2JUjRHM9cpC/?ref=app

2nd Feb 2019, 3:04 PM
BullseyeBE
BullseyeBE - avatar
2 Respuestas
+ 4
You're adding the numbers from 1 to 9 (look at the for loop) to "sum". 1+2+3+...+9 == 45.
2nd Feb 2019, 3:08 PM
Diego
Diego - avatar