Hi guys, I have lingered on these forums for a while but first time posting. I have an assignment that requires me to read in from a text file, copy the values to a struct array, and then print the files out. For the life of me I can't figure out what is going on here, that portion of the code is not outputting at all! The menu is working fine though :).
I'll paste my code, the text file contents, and the header file struct definition below
#include <iostream>
#include <iomanip>
#include <fstream>
#include "functions.h"
usingnamespace std;
int main()
{
//Variable definitions
constint MAX_SIZE = 100; // The maximum array size
int arraySize; //Holds the actual number of elements put in the array
constint EXIT = 9; //Menu choice to quit program
int menuChoice; //Holds menu selection
ifstream inputFile; //Used to initialize the array
Fish myInventory[MAX_SIZE]; //Declaration of array of Fish structs
//Array initialization via the sample .dat file if available
inputFile.open("FishInventory.dat");
for (int count = 0; count < MAX_SIZE; count++)
{
getline(inputFile, myInventory[count].fishName);
inputFile >> myInventory[count].tank;
inputFile >> myInventory[count].quantity;
inputFile >> myInventory[count].price;
}
for(int index = 0; index < arraySize; index++)
{
cout << myInventory[index].fishName << endl;
cout << myInventory[index].tank << endl;
cout << myInventory[index].quantity << endl;
cout << myInventory[index].price << endl;
}
//Program introduction
cout << "Welcome to FishManager! Please select a menu option."
<< endl;
//Loop to allow user to use program until prompted to stop.
do
{
menuChoice = menuFunc();
// Menu Selection Validation
while (menuChoice < 1 || menuChoice > EXIT)
{
cout << "You have entered an invalid menu choice. "
<< endl << "Please enter a valid menu choice: " << endl;
cin >> menuChoice;
}
if (menuChoice != EXIT)
{
switch (menuChoice)
{
case 1:
viewInventory(myInventory, MAX_SIZE);
break;
}
}
} while (menuChoice != EXIT);
return 0;
}
HEADER FILE DEFINITION
struct Fish
{
string fishName;
int tank;
int quantity;
double price;
};
TXT FILE CONTENTS:
Veiltail Betta
5
38
2.23
Fancy Guppies
2
100
1.59
Red Cap Oranda Goldfish
2
25
6.93
Twinbar Solar Flare Swordtail
1
75
3.99