for example in a document there's a list of people who own a cat (marked by a bool).
the user will input if he wants to view the people with cats, or the people without cats:
..
if ( show_people_with_cats )
{ a = people[t].cat; }
else
{ a = !people[t].cat; }
for ( t = 0 ; t < number_of_people ; t++)
{ if ( a ) { cout << people[t].name } }
like that
yes i realize that i can put " if ( people[t].cat ) { cout << ..} " ánd " if ( !people[t].cat ) { ..} "
but then i would have the " cout << .. " part twice.
Well mine is not really a solution. "a = people[t].cat " doesn't work. What variable would 'a' be? A string won't work because if (..) requires a bool. And a bool won't work because I need the program to check either "people[t].cat" or "!people[t].cat" for each person in the for (..) loop.
Basically I want the condition(a) of the second if (..) (the one in the for(..) loop) to be dependant on if the user wants to view the persons with cat, or without.
You need only a if inside the for:
display a person if the user wants to see people with cat and that person has one, or when the user wants to see people with no cats and the person doesn't have one