Listen to
Sane regarding using the index. You don't need to track the maximum value. You only need to track its position within the array, and this allows you to get the value from the array, since you know where it's stored.
Anyways, while other people were replying to you, I whipped up this. It's exactly what you need, but don't just use this for your homework. I'm doing it so you can see how it's done, and I'm only posting code because you've shown you're trying, but if you hand in my work rather than understanding it enough to do it yourself, it'll only hurt you in the long run.
#include <fstream>
#include <iostream>
#include <string>
int main(void)
{
std::ifstream inFile;
std::ofstream outFile;
int myArray[100],
maximumValuePosition = 0,
minimumValuePosition = 0,
count = 0;
inFile.open("inputNums.txt");
if(!inFile) // test if stream is valid, ie is file open?
{
std::cerr << "Unable to open input file, aborting..."
<< std::endl;
return 1;
}
outFile.open("finalResults.txt");
if(!outFile)
{
std::cerr << "Unable to open output file, aborting..."
<< std::endl;
inFile.close();
return 2;
}
while((count < 100) && (inFile >> myArray[count]))
++count;
for(int x=0; x<count; ++x)
{
if(myArray[x] > myArray[maximumValuePosition])
maximumValuePosition = x;
if(myArray[x] < myArray[minimumValuePosition])
minimumValuePosition = x;
}
if(count == 0)
{
outFile << "There were no values in the input file." << std::endl;
}
else
{
outFile << "The maximum value is "
<< myArray[maximumValuePosition]
<< ", found at array index " << maximumValuePosition
<< ".\n";
outFile << "The minimum value is "
<< myArray[minimumValuePosition]
<< ", found at array index " << minimumValuePosition
<< ".\n";
outFile << "There are " << count << " values." << std::endl;
}
inFile.close();
outFile.close();
return 0;
}