I'm currently on my final C++ project for the semester. My assignment is:
===================================================
Programming Assignment 6

Attached Files
File data.txt (0.628 KB)
File sample_dynamic_array.rtf (33.957 KB)

The attached text data file contains a list of numbers between 50 and 150. Create a program that reads those values into an array. Assume that you don't know how many values are in the list and perform the main steps outlined below:

read the file and count how many values there are
based on your count, create an array of the appropriate size using dynamic memory allocation (see attached RTF file for a simple example of creating an array dynamically) Note: you will have to close the file and open it again so that you can read from the beginning again using the statistics library, calculate the minimum, maximum, mean, median, standard deviation, and variance
write the results to another text file

==================================================


So far, I have the bulk of it done, however; I'm having one difficulty. I have set-up found my number of values in the array, made a dynamic memory allotment for my array, and populated it,however, I'm still getting a weird anwser. I'm assuming it may be due to either:

1. Pointers not done correctly
2. Improperly filling in my array.

I've spent a good couple of hours adjusting/trying different things and browsing the web, but I keep getting incorrect anwsers to my functions. I'll post my code below + spoiler the values from the data file, can anyone point me in the right direction or where I'm going wrong?

I'd super appreciate it if so.

Note:I've used the class/library for my functions on programs before so I know there's no error there, only going to post my main .cpp

# include <cmath>
# include <iostream>
# include "Support File.h"
# include <cstdlib>
# include <iomanip>
# include <fstream>
#include<cstdlib>
using namespace std;

int main () 

{ 
	int n(0);
	double temp,data[150],*my_array,min1;
	
	//double *my_array;
	ifstream fin("data.txt");
	ofstream fout("output.txt");
	if(fin. fail())
	{
		cerr<<"could not open input file data";
		exit(1);
	}
	//counts # if values in data.txt
	while(!fin.eof())
	{
		fin>>temp;
		n=n+1;
	}
	cout<<n<<endl;
	//makes a dynamic array of size N
	my_array=new double [n];
	
	//For loop to populate the array
	for(int i=0;i<n;++i)
	{
		fin>>my_array[i];
	}
	  //is that needed?
 min1=minval(my_array,n);
 fout<<min1<<endl;
 //will continue likewise for rest of functions

fin.close();
fout.close();
system("pause");
return 0;

}

Below are the #'s from my data file:
(I couldn't get spoiler tags to work so sorry for the long list ;p
[p]
100
94
93
59
147
117
88
89
126
150
85
99
76
142
121
71
66
112
149
107
78
109
135
129
93
121
89
138
117
132
114
93
124
60
94
116
139
118
99
69
122
103
89
126
139
78
54
51
101
97
92
117
99
121
62
79
52
55
98
100
138
82
76
128
150
100
130
92
56
107
55
53
115
143
70
72
90
83
65
65
87
138
77
71
120
131
122
144
140
66
107
93
115
124
91
67
60
118
90
112
72
133
137
103
126
75
118
89
141
74
108
107
93
134
149
116
60
134
57
148
95
70
127
57
123
124
89
140
100
73
72
142
59
51
110
58
89
72
69
135
147
91
92

One thing strikes me most of all, that you did not, in fact, close and re-open the file as the instructions said would be necessary. This is probably the main reason it isn't working, and the data you are getting is probably garbage that was already in the allocated memory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.