Okay, so the time has come for me to correct a hole in my knowledge about my while loops, namely, why they never seem to be able to check for my != relational operators.
So I was writing a loop for the inventory function of my text adventure when I realized that the best thing I could use to check to see if the player had input certain integers was the != operator. I wrote it like so:
Code:
while (inventory_choice_reference != 1 || inventory_choice_reference != 2 || inventory_choice_reference !=9)
{
cout << "You are currently carrying: \n";
if (healing_potion_reference > 0)
{
cout << "1. Healing Potion (Restores player to full health (10)) \n";
}
if (half_healing_potion_reference > 0)
{
cout << "2. Half Healing Potion (gain 3 health)\n";
}
cout << "Enter the number of the item you'd like to use, or type 9 to exit: ";
cin >> inventory_choice_reference;
if (inventory_choice_reference == 1 && healing_potion_reference == 0)
{
cout << "You don't have one of those.\n";
inventory_choice_reference = 0;
}
if (inventory_choice_reference == 2 && half_healing_potion_reference == 0)
{
cout << "You don't have one of those.\n";
inventory_choice_reference = 0;
}
}
This loops even if the player inputs 9 as the inventory_choice_reference, but I know that inventory_choice_reference is being modified properly because the "You don't have one of those." statements show up fine when you enter 1 or 2, but not 9.
I've had problems like this when putting != statements as loop conditions before. So much so that I usually define loops around case switches a bit like this:
Code:
while (player_choices.tutorial_choice_two > 2 || player_choices.tutorial_choice_two < 1)
{
cout << "Choose an option: \n";
cin >> player_choices.tutorial_choice_two;
cin.ignore();
switch (player_choices.tutorial_choice_two)
{
case 1:
breathe_deep (player_race_reference, player_health_stat_reference, location_reference, healing_potion_reference, half_healing_potion_reference, inventory_choice_reference);
cout << "You open your eyes. /n/nThe mare gives you a nod. \"Good work, your heart rate is down allready.\"\n\n";
break;
case 2:
cout<< "The mare sighs, \"Okay, I'll admit, it DOES seem a bit silly, and it's not like you have a lot of reason to trust me...\nStill, if you ever feel more comfortable with it, I'd reccomend giving it a try.\"\n\n";
break;
}
}
To avoid having to deal with using != even though I know some user might type in 1.5 some day and blow up their computer.
Can anyone tell me what I'm doing wrong here? I could really use the help.