Hello.
I'm having trouble reading text from a file into a struct array.
I have to do much more with this program, but I first need to load the array with the data from the file.
It seems as though it will only get the data from the first college and then when it runs through the loop for the second college, it doesn't proceed to get the data from the file correctly. I feel like this has something to do with the way in which it's reading the text from the file.
The file looks like this:
University of Illinois
0.50 6
0.75 5
0.50 9
0.75 4
1.00 3
University of Iowa
0.90 4
1.00 6
0.90 3
1.00 2
1.25 4
Syracuse University
1.00 3
1.25 5
1.00 2
1.25 6
2.00 4
The Ohio State University
0.80 5
0.90 4
0.80 7
0905 3
1.50 2
University of California
0.75 1
0.85 2
0.75 4
0.85 2
1.00 5
University of Arizona
1.00 2
1.25 6
1.00 7
1.25 3
1.50 2
The file includes the college location name then under each name is 5 lines which contain the soda price and number of sodas in the machine.
Side note: I'm only having the loop run through 2 colleges at the moment - just for testing purposes.
If line getline(statsIn, array[count].location); is outside of the for loop like that, count will not work correctly for the array.
Also, that still does not allow the array to be loaded correctly - doing that will only save the first location, first price, and first number of sodas:
location 1: University of Illinois
price 1: 0.50
num sodas 1: 6
price 2: 0.00
num sodas 2: 0
price 3: 0.00
num sodas 3: 0
....
I know that I'm not using the for loop to it's full potential, but right now I'm just testing to see if the first two locations save, and right now only the first one does.