variable being set to 1 :/

I have a part of my code which reads:
1
2
3
4
5
6
7
8
9
10
11
12
        else if (response1 == "tomahawk" && tomahawk.amount > 0)
        {
            if (monster.fight)
            {

                cout << "1";
            }
            else
            {
                cout << "\nYou cannot use this when not in a fight!\n\n\n";
            }
        }


monster.fight is set to 0 from another part of my code.

After:
1
2
else if (response1 == "tomahawk" && tomahawk.amount > 0)
        {


monster.fight is 0, however when the program runs this next part of code:
if (monster.fight)

monster.fight suddenly is equal to 1. How do I fix this?
Where did you get that idea, that is, how did you determine this?
I dont understand by "what did you determine this"?
He means 'how do you know monster.fight is actually 0?'
@ OP: What part of your code is supposed to set "monster.fight" to 0? Please post that part of your code in your next entry.
monster.fight is inside a class which reads :

1
2
3
4
class monster{
  public:
 int health, fight;
  } monster;


Int my void initialization is specefied that monster.fight = 0 and this initialize runs in the beginning of the code. There is nowhere in the code where monster.fight is being set to 1 at all, it just happens.
Post the code.
There is nowhere in the code where monster.fight is being set to 1 at all, it just happens.


Heap corruption?

Or possibly you're just mistaken?

moorecm is right, we need to see more code.
Is "monster.fight" set to anything in the constructor? Because that if loop should return true on anything except 0.
Are you sure your testing the right executable? I've made this mistake before: copying an executable from the wrong path to a test environment and couldn't figure out why I didn't see my latest changes. Did you try a clean build?
Got it to work!
Last edited on
And the flaw was...?
Topic archived. No new replies allowed.