it suppose to take the user input(a number) and put that item into your item into the inventory(1. hat, puts hat into the inventory). After that I need a loop that will keep adding items into the inventory intill it reaches the max and allow the user to discard one/replace. At the same time, every time the user chooses a item, their health goes down by 10 intill it goes down to 20 and then the person finds a healing potion that restore 100.
I'm having probelms making it take in take the user input and putting that item into the inventory. I have tried to put it into a loop but it doesn't keep the past items. for the health, what would you do? Make a if/else statement..? I'm lost, please help
here what I got
is there a way to print out the list of item to print without cout it?
// Hero's Inventory
// Demonstrates arrays
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int MAX_ITEMS = 10;
string inventory[MAX_ITEMS];
string inventory2 [MAX_ITEMS];
int numItems = 0;
int choice=numItems;
int numItems2=0;
//health
int x=100;
// list of items for input
inventory[numItems] = "sword";
inventory[numItems] = "armor";
inventory[numItems] = "shield";
inventory[numItems] = "knife";
inventory[numItems] = "gun";
inventory[numItems] = "axe";
inventory[numItems] = "hammer";
inventory[numItems] = "armor";
inventory[numItems] = "boots";
inventory[numItems] = "hat";
// list of items for user to pick
cout<< "welcome to RPG inventory2\n";
cout<<"1. sword\n";
cout<<"2. armor\n";
cout<<"3. shield\n";
cout<<"4. knife\n";
cout<<"5. gun\n";
cout<<"6. axe\n";
cout<<"7. hammer\n";
cout<<"8. armor\n";
cout<<"9. boots\n";
cout<<"10. hat\n\n\n";
// inventory choice and health choice
cout<< "please pick a item to add to your inventory\n";
cout<< "health will drop 10 points for every item\n\n";
cin>> choice;
inventory2[numItems2++]=inventory[choice--];
if (numItems2 < MAX_ITEMS)
{
for (int i = 0; i < numItems2; ++i)
cout << inventory2 << endl;
cout << "Your items:\n";
cout << inventory2[numItems2] << endl;
cout<< "your health is now\n";
cout<< x-10<<endl;
}
else
cout << "You have too many items and can't carry another.";
cout << "\nYour items:\n";
int blank;
cin >> blank;
return 0;
}