Modify the original Hero's Inventory I assignment to allow the user to create an inventory which not only holds the name of the objects obtained, but their point values as well. You will do this using a single structure, so that string names and numeric point values may be housed in a single structure. As the items are used, they are removed from the inventory. The avatar may also decide to "trade" an element from his list for a more desirable item. Please add a score variable, so that as the user adds items to this inventory, you add the proper number of points to their score.


Create a program which will create a Hero's Inventory. The program should take the user input (a number) and put that item into the inventory (for example, if the user enters 1. Sword, the program should insert the string "Sword" into the inventory). You will need to add a loop that allows the user to keep adding items into the inventory until it reaches a maximum number of list items, or the user decides to terminate adding.The program should also allow the user to discard/replace an item. If the user chooses to discard an item, the number of points should be deducted from their score.You will need two menus, one with items the user can add to their inventory, and another menu which lists actions they can take 1-Add Item, 2-Delete Item, 3-Swap Item.Everytime there is a change to the inventory, either an item is added, deleted, or swapped, the new inventory/points and total should print.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>
#include <string>

using namespace std;

int main()
{
   
   unsigned int x=100; //health
    const int MAX_ITEMS = 10;
    const int MAX_ITEMS2 =5;
    string inventory[MAX_ITEMS];
    string inventory2 [MAX_ITEMS2];
    int numItems = 0;
    int choice=numItems;
  int numItems2=0;
  char another;

  

 // begin loop
  do
{
    // list of items for input
   
inventory[0] = "sword";
inventory[1] = "armor";
inventory[2] = "shield";
inventory[3] = "knife";
inventory[4] = "gun";
inventory[5] = "axe";
inventory[6] = "hammer";
inventory[7] = "belt";
inventory[8] = "boots";
inventory[9] = "hat";

// list of items for user to pick/see
cout<< "welcome to RPG inventory\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. belt\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-1];
numItems2++;
    cout << "Your items:\n";      
   if (numItems2 < MAX_ITEMS2)
   {
    
    for (int i = 0; i < numItems2; ++i)
    
    
    cout << inventory2[i] << endl;
    
    
    cout << inventory2[numItems2] << endl;
    
    cout<< "your health is now\n";
          x = x - 10; cout << x;
          
          
   }// end if
   else 
   
        
   cout << "You have too many items and can't carry another.";  

// end else


//ending part of loop
  cout << "\n\n\nWould You Like To Play Again? (y/n): ";
cin >> another;

 }while(another == 'Y' || another == 'y') ;// loop
 


 return 0;
}//end main

Do the requirements just one at a time so that you don't get too confused and overwhelmed by the size of that assignment. Don't try to code it all at one time either -- code a few lines, compile, make corrections, compile again until no more errors. Then code a few more lines.

For example, do this part first:

You will do this using a single structure, so that string names and numeric point values may be housed in a single structure. As the items are used, they are removed from the inventory.

Then move on to the next requirement in the assignment.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.