Okay, well, some things to clear up:
(1) The weird solution I had in my posts a few replies back was a workaround to open and process the input file twice to avoid using arrays. If we're going to use arrays anyway, my previous method just becomes bloat here... (it's not wrong, it's just unnecessary).
(2) You are never writing your randomly generated numbers to a file, unlike your original post. You are opening a file for reading called "Numbers.txt", but nowhere in this code are you writing to that file. I was just assuming you were leaving this part out for brevity.
Look back at your first post, you wrote to the file.
1 2 3 4 5
|
ofstream outputFile;
outputFile.open("Numbers.txt");
outputFile << num1 << " " << num2 << " " << num3 << " " << num4 << " " << num5 << " " << num6 << " " << num7 << " " << num8 << " " << num9 << " " << num10;
|
You can do this in a loop instead now...
1 2 3 4
|
for (int i = 0; i < 10; i++)
{
outputFile << nums[i] << ' ';
}
|
You need to combine these things.
Generate the numbers [possibly into an array], write the numbers to a file, close the file, then open that file for reading, read the numbers, find the average.