-1

my program is reading in 2 text files, one is going into an array and one is priming read normally. The one that is being read into an array has an item code, price, quantity, and item name. When the item code matches with the code on the other text document I need to get the price associated with it and cant figure out how.

while (!purchasesFile.eof())
{
    purchasesFile >> PurchaseItem >> purchaseQty;


    cout << purchaseNum << "  " << PurchaseItem << "  " << setw(4) << 
    purchaseQty << "  @ " << dollarSign << endl;

    int n = 0;  
        if (inventoryRec[n].itemCode != PurchaseItem)
        {
            inventoryRec[n+1];
        }
        else 
        {
            cout << inventoryRec[n].itemPrice << endl;
            inventoryRec[n+1];
        }

    if (PurchaseItem == inventoryRec[itemCount].itemCode)
    {
        inventoryRec[itemCount].itemOnHand - purchaseQty;
        purchaseAmount = inventoryRec[itemCount].itemPrice * purchaseQty;

        cout << purchaseAmount << "  " << 
       inventoryRec[itemCount].itemOnHand;

        purchaseCount++;
    }


    purchasesFile >> purchaseNum;
}
purchasesFile.close();
user540393
  • 145
  • 7

1 Answers1

1

There are several statements in your code that do nothing:

inventoryRec[n+1];

inventoryRec[itemCount].itemOnHand - purchaseQty;

What you are looking for is probably something like the STL map

typedef struct inventory_item_t {
    inventory_item_t(const std::string& item_code, double price, int quantity) :
        item_code(item_code),
        price(price),
        quantity(quanity) { }

    std::string item_code;
    double price;
    int quantity;
} inventory_item_t;

typedef std::map<std::string, inventory_item_t> inventory_items_t;

inventory_items_t inventory_items;

inventory_items.insert(make_pair("item1", inventory_item_t("item1", 1.0, 1)));
inventory_items.insert(make_pair("item2", inventory_item_t("item2", 1.1, 2)));
inventory_items.insert(make_pair("item3", inventory_item_t("item3", 1.2, 3)));

inventory_items_t::iterator inventory_item = inventory_items.find("item1");

if(inventory_item != inventory_items.end()) {
    std::cout << "Inventory Item found - item_code: ["
              << inventory_item->first
              << "], price: ["
              << inventory_item->second.price
              << "]"
              << std::endl;
} else {
    std::cout << "Inventory Item not found" << std::endl;
}
Abdul Ahad
  • 826
  • 8
  • 16