I'm implementing a code that takes values from a text file without knowing the number of values in the file. I have to ultimately output these values in another file with their average. I've added checks to see how much the code is running. It isn't reaching the third output namely "3.Here". I've tried changing the loop from while (!(input.eof())) to do while (//bool variable that keeps track of if it reaches end of file)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
cout << "1.Here" << endl ; //first check to see output
ifstream input;
input.open("input1.txt");
int numberofvalues = 0;
cout << "2.Here" << endl ; //second check to see output. Its running till here
while(!(input.eof()))
{
numberofvalues ++;
}
cout << "3.Here" << endl ; //not running here
cout << "The numberofvalues: " << numberofvalues ;
int arr[numberofvalues] ={};
for (int i=0; i<numberofvalues;i++)
{
int number;
input >> number;
arr[i] = number;
}
}