Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNightCreature83

Posted 13 November 2012 - 09:15 AM

Right nevermind I have my python hat on today and not my C++ hat Posted Image

The problem you are having is that the iterator returned by inventory.at(choice) not necessarily needs to be inventory.end(), if you change the end into an inventory.at(choice) it should work. Be careful though as choice can index outside of your inventory vector as maximum choice is defined as inventory.size() + 1, see the output loop above in which you create the choice menu.

Also more info on find here

#3NightCreature83

Posted 13 November 2012 - 09:15 AM

Right nevermind I have my python hat on today and not my C++ hat :(

The problem you are having is that the iterator returned by inventory.at(choice) not necessarily needs to be inventory.end(), if you change the end into an inventory.at(choice) it should work. Be careful though as choice can index outside of your inventory vector as maximum choice is defined as inventory.size() + 1, see the output loop above in which you create the choice menu.

Also more info on find here

#2NightCreature83

Posted 13 November 2012 - 09:12 AM

Right nevermind I have my python hat on today and not my C++ hat :(

#1NightCreature83

Posted 13 November 2012 - 09:10 AM

Instead of
if (find(inventory.begin(), inventory.at(choice), healingPotion.itemName) != inventory.end())
					    cout << "You used a healing potion!";
			    else
					    cout << "FIERY BALLS OF JOY!";
			    break;
	    case 2:
			    cout << "Such a jerk, you are." << endl;
					    break;
	    }
aren't you just doing
//Check for valid ranges on choice above this line
if (inventory[choice - 1].itemName == healingPotion.itemName )
	 cout << "You used a healing potion!";
else
	 cout << "FIERY BALLS OF JOY!";

PARTNERS