swapping vector int's and vector strings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fishirboy
    New Member
    • Mar 2013
    • 48

    #1

    swapping vector int's and vector strings

    I want to have it so that when i ask for the person witch item they want to drop on the ground it goes into another vector that i can pick back up the item if they want it back and erase when they walk away.

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <vector>
    #include <string>
    #include <fstream>
    #include <cmath>
     
    using namespace std;
     
        struct InventoryItem
    {
        string name;
        int weight;
    	int price;
    };
     
    int main()
    {
     
        vector<InventoryItem> MyStuff;
    
    	//Money
    	InventoryItem mon;
    	mon.name = "Runes";
    	mon.weight = 1;
    	mon.price = 1;
    	//Item 1
        InventoryItem obj;
        obj.name = "flour";
        obj.weight = 100;
    	obj.price = 10;
    	//Item 2
    	InventoryItem obj2;
    	obj2.name = "wool";
    	obj2.weight = 50;
    	obj2.price = 20;
    	//Item 3
    	InventoryItem obj3;
    	obj3.name = "sword";
    	obj3.weight = 150;
    	obj3.price = 50;
    
    
        int num;
        int del;
        int asdf;
        string name;
     
        MyStuff.push_back(obj); //add item 1 to inventory
    	MyStuff.push_back(obj2); //add item 2 to inventory
    	MyStuff.push_back(obj3); //add item 3 to inventory
     
        vector<InventoryItem>::const_iterator iter;
        vector<InventoryItem>::iterator myIterator;
     
        cout << "\t\t\t\t*Inventory Wight*\n\n";
        cout << "Your inventory, pounds and price:\n";
     
        asdf = 0;
            for (iter = MyStuff.begin(); iter != MyStuff.end(); ++iter)
            {
                ++asdf;
                cout << asdf << ". " << (*iter).name << " | Weight: " << (*iter).weight << " | Price: " << (*iter).price << "\n";
            }
    		cout << "\nYou find a market...\n";
    		market:
    		cout << "what do you want to do?\n\n";
    		cout << "1-look at inventory\n";
    		cout << "2-look at what is for sale\n";
    		cout << "3-leave\n";
    
    		cout << "Choice: ";
    		cin >> num;
    		system("CLS");
    		switch ( num )
    		{
    			case 1:
    				asdf = 0;
    				for (iter = MyStuff.begin(); iter != MyStuff.end(); ++iter)
    				{
    					++asdf;
    					cout << asdf << ". " << (*iter).name << " | Weight: " << (*iter).weight << " | Price: " << (*iter).price << "\n";
    				}
    					cout << "\nWhat do you want to do?\n\n";
    					cout << "1-Back\n";
    					cout << "2-drop an item\n";
    					cout << "3-pick up and item on the ground\n";
    					cout << "Choice: ";
    					cin >> num;
    
    					switch ( num )
    					{
    					case 1:
    						system("CLS");
    						goto market;
    						break;
    					case 2:
    						cout << "\nWhat do you want to drop?\n";
    
    						asdf = 0;
    						for (iter = MyStuff.begin(); iter != MyStuff.end(); ++iter)
    						{
    							++asdf;
    							cout << asdf << ". " << (*iter).name << "\n";
    						}
    						cout << "Pick Item: ";
    						cin >> num;
    						MyStuff.
    						break;
    					case 3:
    						if (0)
    						{
    
    						}
    						else
    						{
    
    						}
    						break;
    					}
    				break;
    			case 2:
    				cout << "hi";
    				break;
    			case 3:
    				cout << "You walk away into the sunset.\n";
    				break;
    		}
    system("pause");
        return 0;
    }
  • fishirboy
    New Member
    • Mar 2013
    • 48

    #2
    I am working on this for a school project and for my entertainment. I would hope to have a little help being pushed in the right direction.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Is this inventory a game inventory rather than a real one at a business?

      Comment

      • fishirboy
        New Member
        • Mar 2013
        • 48

        #4
        Game inventory, I will be adding a combat system and then adding a story over it.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Probably keeping a vector for each player is reasonable. You might consider adding members to the InventoryItem struct for the state of the item. Maye a bool where true is dropped and false is not dropped.

          However, we have exceeded the subject of this thread which was initialy about vectors with strngs and ints. If you need to pursue another subject, then starting new thread is appropriate. Good luck on your adventure.

          Comment

          Working...