- 2

I'm not understanding this. How's num used here??

23rd Dec 2020, 3:24 PM
Adarsh Saurabh
Adarsh Saurabh - avatar
6 odpowiedzi
+ 3
num is a variable here used to control the loop. In other words the value of 'num' variable will decide whether the code inside loop will execute or not as after each execution the value of num is increasing by 1 so the loop will not continue to run after a specific number of executions. Thank you
23rd Dec 2020, 3:30 PM
Hardik Sharma
Hardik Sharma - avatar
+ 2
Where? Please upload your question properly so that community can help you.
23rd Dec 2020, 3:26 PM
Hardik Sharma
Hardik Sharma - avatar
+ 1
int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; return 0; }
23rd Dec 2020, 3:27 PM
Adarsh Saurabh
Adarsh Saurabh - avatar
0
What is num doing here I mean how is it interacting with number
23rd Dec 2020, 3:28 PM
Adarsh Saurabh
Adarsh Saurabh - avatar
0
Ok
23rd Dec 2020, 5:06 PM
Adarsh Saurabh
Adarsh Saurabh - avatar