473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5. #include <fstream>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10.     struct InventoryItem
  11. {
  12.     string name;
  13.     int weight;
  14.     int price;
  15. };
  16.  
  17. int main()
  18. {
  19.  
  20.     vector<InventoryItem> MyStuff;
  21.  
  22.     //Money
  23.     InventoryItem mon;
  24.     mon.name = "Runes";
  25.     mon.weight = 1;
  26.     mon.price = 1;
  27.     //Item 1
  28.     InventoryItem obj;
  29.     obj.name = "flour";
  30.     obj.weight = 100;
  31.     obj.price = 10;
  32.     //Item 2
  33.     InventoryItem obj2;
  34.     obj2.name = "wool";
  35.     obj2.weight = 50;
  36.     obj2.price = 20;
  37.     //Item 3
  38.     InventoryItem obj3;
  39.     obj3.name = "sword";
  40.     obj3.weight = 150;
  41.     obj3.price = 50;
  42.  
  43.  
  44.     int num;
  45.     int del;
  46.     int asdf;
  47.     string name;
  48.  
  49.     MyStuff.push_back(obj); //add item 1 to inventory
  50.     MyStuff.push_back(obj2); //add item 2 to inventory
  51.     MyStuff.push_back(obj3); //add item 3 to inventory
  52.  
  53.     vector<InventoryItem>::const_iterator iter;
  54.     vector<InventoryItem>::iterator myIterator;
  55.  
  56.     cout << "\t\t\t\t*Inventory Wight*\n\n";
  57.     cout << "Your inventory, pounds and price:\n";
  58.  
  59.     asdf = 0;
  60.         for (iter = MyStuff.begin(); iter != MyStuff.end(); ++iter)
  61.         {
  62.             ++asdf;
  63.             cout << asdf << ". " << (*iter).name << " | Weight: " << (*iter).weight << " | Price: " << (*iter).price << "\n";
  64.         }
  65.         cout << "\nYou find a market...\n";
  66.         market:
  67.         cout << "what do you want to do?\n\n";
  68.         cout << "1-look at inventory\n";
  69.         cout << "2-look at what is for sale\n";
  70.         cout << "3-leave\n";
  71.  
  72.         cout << "Choice: ";
  73.         cin >> num;
  74.         system("CLS");
  75.         switch ( num )
  76.         {
  77.             case 1:
  78.                 asdf = 0;
  79.                 for (iter = MyStuff.begin(); iter != MyStuff.end(); ++iter)
  80.                 {
  81.                     ++asdf;
  82.                     cout << asdf << ". " << (*iter).name << " | Weight: " << (*iter).weight << " | Price: " << (*iter).price << "\n";
  83.                 }
  84.                     cout << "\nWhat do you want to do?\n\n";
  85.                     cout << "1-Back\n";
  86.                     cout << "2-drop an item\n";
  87.                     cout << "3-pick up and item on the ground\n";
  88.                     cout << "Choice: ";
  89.                     cin >> num;
  90.  
  91.                     switch ( num )
  92.                     {
  93.                     case 1:
  94.                         system("CLS");
  95.                         goto market;
  96.                         break;
  97.                     case 2:
  98.                         cout << "\nWhat do you want to drop?\n";
  99.  
  100.                         asdf = 0;
  101.                         for (iter = MyStuff.begin(); iter != MyStuff.end(); ++iter)
  102.                         {
  103.                             ++asdf;
  104.                             cout << asdf << ". " << (*iter).name << "\n";
  105.                         }
  106.                         cout << "Pick Item: ";
  107.                         cin >> num;
  108.                         MyStuff.
  109.                         break;
  110.                     case 3:
  111.                         if (0)
  112.                         {
  113.  
  114.                         }
  115.                         else
  116.                         {
  117.  
  118.                         }
  119.                         break;
  120.                     }
  121.                 break;
  122.             case 2:
  123.                 cout << "hi";
  124.                 break;
  125.             case 3:
  126.                 cout << "You walk away into the sunset.\n";
  127.                 break;
  128.         }
  129. system("pause");
  130.     return 0;
  131. }
  132.  
Mar 30 '13 #1

✓ answered by weaknessforcats

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.

4 1226
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.
Mar 30 '13 #2
weaknessforcats
9,208 Expert Mod 8TB
Is this inventory a game inventory rather than a real one at a business?
Mar 30 '13 #3
Game inventory, I will be adding a combat system and then adding a story over it.
Mar 30 '13 #4
weaknessforcats
9,208 Expert Mod 8TB
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.
Mar 30 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: ding feng | last post by:
I am a beginner. So this question could be very stupid. Would anyone help me to solve this problem? A formatted txt file is read. Then i need to look into a vector who is a member of a class to...
4
by: Angela | last post by:
It's late. Why is the compiler saying that this is the wrong syntax: vector<vector<cIndicatorValue>> ranks; One other question: If I want to access one of cIndicatorValue's functions, I have...
18
by: John Black | last post by:
Hi, I am not familiar with for_each very well, suppoase I have a vector<pair<unsigned int, unsigned int> > vec1 and the contents are {<0x00000000, 0x000000FF>, <0x10000000, 0x2FFFFFFF>} what...
9
by: John Guo | last post by:
Hi all, Please help see why this snippet does not compile. Thanks a lot. John #include <string> #include <vector> namespace PatternMsg { std::vector<std::string> msg(17);
4
by: fatgirl.brown | last post by:
Hi all, I am attempting to initialize a vector of a vector in a constructor with some clean-looking syntax and am not sure of how to go about this. For instance: double weight; vector<...
9
by: Jess | last post by:
Hello, I tried to clear a vector "v" using "v.clear()". If "v" contains those objects that are non-built-in (e.g. string), then "clear()" can indeed remove all contents. However, if "v"...
1
by: OriginalCopy | last post by:
This is a demonstrative code which could be used for debugging purposes. And yet I don't know how to insert the necessary data on line 63, purely syntactically speaking ? I'm a beginner with STL, and...
1
by: bmc | last post by:
How can we convert c++ vector to java vector in native method?
2
by: danime91 | last post by:
So I'm doing this assignment for a class, and need to write a function that will basically find all elements of a vector in another vector in the same exact order, then return the starting position...
1
by: Daniel Matias | last post by:
Vector v = new Vector(); Vector n = new Vector(); System.out.print(" "); w = input.nextInt();//this is for receiving the width System.out.print(" "); h = input.nextInt();//this is for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.