I'm a first year student and im busy with a coding exercise but cant seem to crack the case.
when reading from number.dat which is 20 random numbers, i get them read into the array and I print them just for diagnostics at this stage but my print of the data in the array is completely messed up.
Any help is much appreciated.
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
ifstream in_stream;
ofstream out_stream;
int array_size = 20;
int position = 0;
double numbers[array_size];
//Check input and output file.
in_stream.open("Number.dat");
if (in_stream.fail())
{
cout << "Input file opening failed";
exit(1);
}
//array to read data from array as long as we dont reach the end of file marker
while(! in_stream.eof() && position < array_size)
{
in_stream >> numbers[position];
position++;
cout << position << " = "
<< numbers[position] << endl;
}
}