But an even better idea is to not use a #define for this purpose. Make a const variable instead, but not a global one, put it in main:
constunsignedint MAX_UNI = 1000;
Notice I have as an unsigned type, this is a good idea for anything involving size, or indeed anything that shouldn't be negative. One could use std::size_t also.
Btw, I found your error by using cpp.sh (the gear icon top right of the code) with all 3 warning levels on. It detected errors before whatever options you were using. So, set your warnings levels to a high level - warnings are your friend :+)
Have you learnt about struct yet? Instead of having lots of parallel arrays, you can have an array of struct.
And no, I haven't learned struct yet. But will plan to.
I corrected it, and I took your suggestion to make it a const variable, and it worked.
The program compiled and work, but apparently it is not extracting the data correctly.
I edited my original post, to reflect the recent changes and also the current issue.
Trying to get the program to read 'Princeton University' and put it into variable universityname.
Then skip a line and read 'NJ', put it into variable state,
then read 'Princeton', put it into variable city,
then skip a line and read the 4 data points.
I am guessing it has something to do with how I am doing the ignore() functionalities.
The program outputted:
P
Purpose: Universities Analysis
Press any key to continue . . .
I edited my original post, to reflect the recent changes and also the current issue.
Please don't do this, it makes following the thread almost impossible, instead add the modified code into a new post.
In your read loop I would move that first .ignore() to the end of the loop, because the first time through the loop it really isn't required. I also doubt that the second .ignore() is even required.
So I am still having trouble how to read a text file line by line and extracting certain text into certain variables.
I tried googling, but there is no clear perfect example to do it, and people seems to be struggling also.
For example:
Princeton University
NJ Princeton
41820 8014 0.0740 0.98 0.97
Harvard University
MA Cambridge
43838 19882 0.0580 0.97 0.97
I know the basic structure, which is probably,
inFile >> universityname[count] >> state[count] >> city[count] >> etc, etc...
but how do I 'skip' a line, and then repeat the whole process again?
This might be a worthwhile pattern to follow. Your breakup into data pieces is probably not the same but that's a matter of adapting it, as for indexing and putting into an array(s).