+ 2

can you pass a function through a while loop?

after creating a function to check if any elements in the array are either true or false, I need to pass the function through the while loop to run only if the function returns false. can this be done? the project is to create an airline and only continue to run if there is available seating. After all the seats are filled, the function would return true, quitting the while loop. This is what I have so far: https://code.sololearn.com/cCftD4xKPhyg If there is a better way of doing this, please let me know

8th Apr 2022, 5:26 PM
David
David - avatar
5 ответов
+ 3
This works like if any seat in empty or not set (false), it return false else return true... bool seating(bool array[]) { for (int i = 0; i < 10 ; i++) { if (array[i] == false) { return false; } } return true; }
8th Apr 2022, 6:06 PM
Jayakrishna 🇮🇳
+ 3
No. Sry. I did not checked fully.. array[i] you declared bool array so either you assign true or false. If seat is alloted then set to true. Otherwise it remain false.. On any seat is false, that means not filled all seats.. in loop, hoping only 10 seats available, use condition i<10 instead of i<array[10] i is values ranges from 0 to 9 ( array indexes).. David either 1 or 2 ? I don't understand this? what you mean here?.
8th Apr 2022, 6:19 PM
Jayakrishna 🇮🇳
+ 2
Jayakrishna🇮🇳 Oh sorry. I meant 0 or 1. 0 being false and 1 being true
8th Apr 2022, 6:24 PM
David
David - avatar
+ 1
Jayakrishna🇮🇳 in the line: if (array[i] == false) should i set that to 1 instead? Because “i” is going to be either 1 or 2
8th Apr 2022, 6:10 PM
David
David - avatar
+ 1
Jayakrishna🇮🇳 im making thr changes. Appreciate your help.
8th Apr 2022, 6:25 PM
David
David - avatar