I am writing a program that keeps inventory for a made up book store. I am using a dynamic 2d array to hold the data. Here is what I have so far. The program compiles, but when I try and output the data, nothing shows up.
struct StoreInventory
{
string title;
int copies;
double wholesalePrice;
};
void ListBooks(StoreInventory **inventory, int count, int columns);
int main()
{
// Declare Variables
ifstream inFile;
ofstream outFile;
char menuChoice;
int size = 5, count = 0, columns = 3, rows;
// Initialize and Set up rows in Dynamic Array
StoreInventory **inventory = new StoreInventory* [rows];
// Set up columns in Dynamic Array
for(int row = 0; row < rows; row++)
inventory[row] = new StoreInventory[columns];
inFile.open("inventory.dat");
inFile >> (inventory[0][0]).title >> (inventory[0][1]).copies >> (inventory[0][2]).wholesalePrice;
while(inFile)
{
count++;
inFile >> (inventory[count][0]).title >> (inventory[count][1]).copies >> (inventory[count][2]).wholesalePrice;
}
......
void ListBooks(StoreInventory **inventory, int count, int columns)
{
for(int row = 0; row < count; row++)
{
for(int col = 0; col < columns; col++)
cout << (inventory[row][col]).title << " " << &(inventory[row][col]).title;
cout << endl;
}
}
I left some stuff out like the menu to this program because I tested it thoroughly and it works. If needed I can put the entire program. I am not seeking the outright answer to my problem, but maybe some nice hints so that I can study this further and learn it on my own would be appreciated.
Edited in to add that I am keeping track of book title, number of copies, and wholesale price.
I have beat myself up over this a good part of the day. I took a shower, came back and looked at it again. I asked myself, why am I using a 2d array for this at all? I think just a dynamic array would fit the bill. I think that is my major problem, I wll try that right now.