Need help changing a stored variable inside a string:
Both parts of the code are on here but if you want to see with syntax colouring i have uploaded onto codepad
Click here for code with syntax highlights
Here are the variables so it isnt confusing:
Code:
string UserName;
string PlayerInv = "\nInventory:";
string ARROW = "\nArrows x";
stringstream ss;
int Money;
int PlayerHP = 75;
int Foodx = 0;
int Drinkx = 0;
int arrowx = 0;
bool arrow_owned = false;
enum ShopMisc{Arrow = 2, Food = 10, Drink = 10,WeaponPoison = 35,} //Ignore all but arrow
What i want to do is that if the user chooses to buy arrows and they already have some in there inventory [arrow_owned == true] instead of when they buy more i dont want it to say this in the inventory
Example:
Inventory:
Food
weapon poison
Arrow x10 <<<<
Arrow x23 <<<<
Bow
instead when they are already owned i want the variable 'arrowx' to be changed by arrowchoice[how many more the user chooses to buy]
ive been stuck with it for AGEESSSS so decided to join this forum in search of help :S
Here is the main part of code im stuck with:
Code:
case 1:
{
cout << "How many Arrows would you like? :";
cin >> arrowchoice;
Sleep(1000);
cout << "\nYou have chose "<<arrowchoice<< " Arrows costing " <<(Arrow*arrowchoice)<<" Gold peices\n";
if(Money - (Arrow*arrowchoice) >= 0)
{
if(arrow_owned == true)
{ //just a guess so its obv wrong
ss >> PlayerInv >> ARROW >> arrowx;
Money = (Money - (Arrow*arrowchoice));
cout << "You now have: " << Money << " Gold peices\n";
arrowx = (arrowx + arrowchoice);
ss << PlayerInv << ARROW << arrowx;
PlayerInv = ss.str();
goto SHOPEND;
}
Money = (Money - (Arrow*arrowchoice));
cout << "You now have: " << Money << " Gold peices\n";
arrowx = (arrowx + arrowchoice);
ss <<PlayerInv << ARROW << arrowx;
PlayerInv = ss.str();
arrow_owned = true;
goto SHOPEND;
}
else
{
cout << "You dont have enough gold for "<< arrowchoice << "arrows\n";
goto SHOPEND;
}
}
All works fine apart from the part if(arrow_owned==true){}
it charges for more than 1 and doesnt increase the amount owned
any help ?