|
| bananaHUNT (10) | |
| How would you do something like this: if ( bool_a ) { a = condition; } else { a = !condition; } if ( a ) { ... } | |
| Bazzy (4111) | |
| Can you explain a bit more? | |
| bananaHUNT (10) | |
| 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. | |
Last edited on | |
| computerquip (877) | |
| I think he means that he doesn't know what you want. It sounds like your solving your own problem. | |
| bananaHUNT (10) | |
| 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. | |
Last edited on | |
| Bazzy (4111) | |
| 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 | |
| bananaHUNT (10) | |
| But then I still have the "cout << .." part twice, no? | |
| jsmith (3802) | |||
I don't think there is a language-specific thing that will do what you want. But you can design a solution.
| |||
| Bazzy (4111) | |||
| You would need a logical nxor to have a single cout eg:
| |||
Last edited on | |||
This topic is archived - New replies not allowed.
