0

What for num++ in this code?

#include <iostream> using namespace std int main() { int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; return 0; }

3rd Mar 2018, 7:48 AM
Egor Shadelko
2 Answers
0
num must be 6 in the end
3rd Mar 2018, 7:52 AM
Š¢ŠøŠ¼ŃƒŃ€ ŠŠ»ŠøŠµŠ²
Š¢ŠøŠ¼ŃƒŃ€ ŠŠ»ŠøŠµŠ² - avatar
0
Num++ adds the value of num by 1 in every loop until the loop is terminated (when num becomes 6). It basically means: num=num+1.
3rd Mar 2018, 8:06 AM
Sedai