Okay, so the premise is that this place contains items for sale, and has five of everything that it sells. The inventory is brought in from a file and with parallel arrays you set up the item names with the inventory in stock. I have that all down, but now I need to get a cin loop going which I'm not sure how to do and if the user enters an item name that's in the array, the stock for that item is decremented one. My current troubles aside from not sure how to get a cin loop going, is that I can't even figure out how to let the user enter a string and see if it matches any of the item names in the array. Here's the code I have written:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int MAX_ITEMS = 1000;
string filename;
string names [MAX_ITEMS];
int inventory [MAX_ITEMS];
string item;
string item2;
int count;
int count2 = 0;
int inventorycount = 5;
int main()
{
ifstream inFile;
cout << " ** 5-of-Everything Department Store ** " << endl;
cout << "What's the inventory file?" << endl;
getline(cin, filename);
inFile.open(filename.c_str());
count = 0;
getline(inFile, item);
while (inFile)
{
names[count] = item;
count++;
inventory[count2] = inventorycount;
count2 ++;
getline(inFile, item);
}
inFile.close();
cout << "What is being sold?" << endl;
cin >> item2;
if (item2 == names[count])
{
cout <<"Sold!" << endl;
}
else
{
cout <<"Sorry not in stock!"<< endl;
}
return 0;
}
I'm not sure what to be comparing after something has been entered from the user, to check if that item name exists in the array. Also the user is supposed to be allowed to enter the item name in all lowers even though in the inventory file it may be spelled with capital letters. I've been messing around with tolower, but it says it expects an int where I've tried to use a string. So, not sure how to do a tolower on a string, of if it's even possible.