is there a way to reset a boolean variable?

Jul 29, 2016 at 9:38pm
originally i have a boolean variable set to false, and if it met a certain condition, the boolean variable would set to true.
so, is there something i can use to essentially reset the boolean variable back to false without actually having to manually set that variable back to false or making a second boolean variable?

note: i'm pretty new to c++ and i'd appreciate it if you guys gave me a really simplified answer (if there really is a way to reset the boolean variable)
Last edited on Jul 29, 2016 at 9:40pm
Jul 29, 2016 at 9:41pm
Hi,
Use this :
ok = !ok;
Jul 29, 2016 at 9:42pm
Does that help? :)
Jul 29, 2016 at 9:42pm
oh okay lol that makes sense i don't know why i didn't think of that before, i'll try that out now
Jul 30, 2016 at 12:29am
okay another question, is it possible to erase or delete a value that's in a variable?
like let's say that int num=3. is there a way where i can delete the value from it and just have it as if i never assigned it anything in the first place?
Jul 30, 2016 at 1:07am
You always want to assign a value to an int variable, even if you're not using it now. While setting up a variable and you don't want it to have a value yet, just set it up as: int num = 0. And f you no longer want it to be 3 just change it back: num = 0.
Jul 30, 2016 at 1:13am
closed account (48T7M4Gy)
Unless the variable is defined as a constant you can re-assign the variable to any compatible value you like. But there is no need to if you don't intend to use it again.

You re-assign the initialised int num = 3; by the statement num = 5;
Last edited on Jul 30, 2016 at 1:14am
Jul 30, 2016 at 6:31am
Note that this line of code ok = !ok; sets the variable to the opposite value.

If ok is true it sets it to false.
If ok is false it sets it to true.

That means it will not actually reset the variable to the value that it was originally initialized to, unless it happens to have the opposite of that value.
Last edited on Jul 30, 2016 at 6:32am
Topic archived. No new replies allowed.