I have a file with a random number of integers, all on their own line, and the program needs to read them in. All is good, except being able to tell the computer where the end of the file is at. For a test file I put 21 numbers (positive and negative) in random order, and the program says there is 25 numbers, with a very small value for the highest and lowest number (ie -124325).
Code:
myfile>>inarray[n];
high = inarray[n];
low = inarray[n];
while(inarray[n] != EOF){ //also tried while(inarray[n] != NULL)
n++;
myfile>>inarray[n];
if(high < inarray[n])
high = inarray[n];
if(low > inarray[n])
low = inarray[n];
}
cout<<"low: "<< low <<endl;
cout<<"high: "<< high <<endl;
cout<<"max: "<< n <<endl;