I have "items" in an "inventory" array, the inventory array is a struct composed of several different parts however I want to be able to search for a certain part of the array by using the item name alone (so I can make functions to delete, purchase, etc.) I was wondering how I would go about doing so and if it would instead be easier to convert the struct to a class instead if need be. Keep in mind a good amount of it is still a work in progress, I'm specifically aiming for the removeItem function currently however. Thanks in advance for any and all help!
my code is here:
#include "integerstore.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void removeItem(Item);
int buyItem(Item, int);
int sellItem(Item, int);
void stockReport(Item);
struct Item
{
string name;
float cost;
float price;
int quantity;
};
int main()
{
Item inventory[100];
int total = 0;
string cmd;
cout << "Welcome to inventory management. To add a new inventory item type add, to remove and item from inventory type remove, to add to inventory quantity type buy, to mark a sold item type sell, to see the current inventory report type report and to end the program type stop" << endl;
do
{
cin >> cmd;
if (cmd == "add")
{
cout << "Enter the new item's name";
cin >> inventory[i].name;
cout << endl;
cout << "Enter the new item's cost";
cin >> inventory[i].cost;
if (inventory[i].cost <= 100.00)
{
break;
}
else
{
cout << "Cost of item may not exceed 100.00, please reenter.";
cin.clear();
}
cout << endl;
cout << "Enter the new item's selling price";
cin >> inventory[i].price;
if (inventory[i].price <= 100.00)
{
break;
}
else
{
cout << "Selling price may not exceed 100.00, please reenter.";
cin.clear();
}
cout << endl;
i++;
}
else if (cmd == "remove")
removeItem(inventory[100]);
else if (cmd == "buy")
buyItem(inventory[100], total);
else if (cmd == "sell")
sellItem(inventory[100]);
else if (cmd == "report")
stockReport(inventory[100]);
else if (cmd != "stop")
cout << "invalid";
}
while (cmd != "stop");
system ("pause");
return 0;
}
int buyItem(Item w, int w2)
{
string itemName;
cout << "Enter the item name of which you wish to add more stock to" << endl;
cin >> itemName;
}
int sellItem(Item x, int x2)
{
}
void removeItem (Item y)
{
string itemName;
cout << "Enter the item name you wish to remove from the inventory" << endl;
cin >> itemName;
}
void stockReport(Item z)
{
}