View Single Post
Old Dec 4th, 2007, 4:42 PM   #5
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 532
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: read integers from file into an array

>>do i use the else if statement
No, just use another variable and statement like I did for the max value. I wouldn't use the else statement because maybe the current value just read affects both min and max.
int max = 0;
int min = 0;
int i = 0;
while( inFile >> myArray[i]) 
{
     if( i == 0) // first time throug
    {
         max = min = myArray[i];
    }
    if( myArray[i] > max)
         max = myArray[i];
    if( myArray[i] < min)
         min = myArray[i];
    ++i;
}

And you forgot to add code tags
Ancient Dragon is offline   Reply With Quote