0
int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << tota
I can't understand this 😑 why is the output 10 when the input is 2?
2 odpowiedzi
+ 2
If you keep inputting 2, you will get 10. This is because the loop runs 5 times, and it adds 2 to total five times.
Iteration trace (num: total)
1:2
2:4
3:6
4:8
5:10
0
thanks it's much better now