+ 1
Who can explain 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; }
1 ответ
+ 1
You are asking the user to input 5 int values and after each input you add it to the total variable so eventually you're printing the total var after you increment each input to the total.
for example: 5 4 7 6 3
total += 5. num= 1
total += 4. num= 2
total += 7. num= 3
total += 6. num= 4
total += 3. num= 5
as you can see num is five so it exits the while loop and prints on the screen the sum of the inputs (25)