+ 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
5 odpowiedzi
+ 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;
}
+ 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?.
+ 2
Jayakrishna🇮🇳 Oh sorry. I meant 0 or 1. 0 being false and 1 being true
+ 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
+ 1
Jayakrishna🇮🇳 im making thr changes. Appreciate your help.