Struct Arrays.

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <iomanip>
#include <fstream>
#include "functions.h"

using namespace std;



int main()
{
    //Variable definitions
    const int MAX_SIZE = 100;   // The maximum array size
    int arraySize;              //Holds the actual number of elements put in the array
    const int 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
for(int index = 0; index < arraySize; index++) Where do you assign any value to arraySize?
number of fish name may not be equal to MAX_SIZE.
so you have to count fish names, for loop of line24 should run that amount of times.
Topic archived. No new replies allowed.