what does this mean? (C++) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what does this mean? (C++)

int All_Incl_Total(Room r[], int n) { int total=0; for(int i=0; i<n; i++) { if(r[i].GetAll_Inclusive()) { total++; } } return total; } We have this function and what i dont understand is what does the total++ actually do inside the for?Also how does that if work? Like does it compare the condition to anything?

1st Dec 2022, 10:12 PM
Andrew Sempros
Andrew Sempros - avatar
1 Answer
+ 2
The total variable is a counter that stats from zero. The for loop will walk through all elements of the Room array. I assume the GetAll_Inclusive() method return a boolean (true or false) value. So in the if condition it is checked for each element if this is true, and if yes, the total value is incremented by one. So at the end you get the number of how many rooms are all inclusive.
2nd Dec 2022, 5:47 AM
Tibor Santa
Tibor Santa - avatar