I have followed a book called C++ through Game Programming. Where I found a program called Hero's Inventory. I wanted to modify that program, but it I have a problem.
In the program you get to choose either if you want to trade your sword for a battle axe or not. But whatever you push, you accept the trade. So if you answer is N, you accept the trade. I just can't understand why..
int tradeSwordAxe;
cout << "\nSomeone ask if you want to trade your sword for an battle axe. (y/n)\n";
cin >> tradeSwordAxe;
tradeSwordAxe is of type int. When you enter a letter the input operation fails, and your if tests against the junk that was in tradeSwordAxe when you defined it, but didn't initialize it. The chances of that being any value you're expecting is rather small.
int tradeSwordAxe;
cout << "\nSomeone ask if you want to trade your sword for an battle axe. (y/n)\n";
cin >> tradeSwordAxe;
You defined tradeSwordAxe as int. Then you enter input as, for example, Y, input stream cin sees that there is no a number and it stops to read and assigns to tradeSwordAxe value 0.