Well, the reason you are getting 1.#IO is the call to deviation
|
cout << "Standard Deviation : " << deviation(summ, avg, size) << endl;
|
I believe that size will be zero, and hence.
involves division by zero.
Looking at your code it appears that you are trying to count the number of elements in the loop
1 2 3 4 5 6 7
|
inputfile >> N;
while(!inputfile.eof())
{
standDeviation[size] = N;
size++;
inputfile >> N;
}
|
This fails because the previous loop to input into List will have caused inputfile.eof() to become true, hence this loop is never executed, and size remains zero.
The check for eof() and need to count the number of elements suggests you do not have a fixed number of elements, and so should be using dynamic memory allocation, but assuming you know it will always be 1000 or less you can stick with the simple static arrays and a counter (it's just not very efficient).
I woudl replace
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
double List[Num_List];
....
for (int count=0; count < Num_List; count++)
inputfile >> List[count];
float standDeviation [100];
inputfile >> N;
while(!inputfile.eof())
{
standDeviation[size] = N;
size++;
inputfile >> N;
}
|
by
1 2 3 4 5 6 7 8 9
|
double standDeviation [Num_List];
inputfile >> N;
while((!inputfile.eof()) && (size<Num_List))
{
standDeviation[size] = N;
size++;
inputfile >> N;
}
|
This will load the array standDeviation and set size. The additional check in the while condition is to avoid overrunning the array bounds.
Note that I have declared standDeviation as double - it probably makes sense to standardise on double throughout (IE replace all float by double).
I woudl also avoid using varaibles inside a function with the same name as the function (or any other functions). The compiler should be able to cope, but the code is less obvious.
1 2 3 4 5 6 7 8 9 10 11
|
float sum (float vector[], int size)
{
float theSum;
theSum = 0.0;
for (int N = 0; N < size; N++)
{
theSum +=vector[N] ;
}
return theSum;
}
|
dittio for average.
Finally, you are using ceil {round up} when you probably want pow {raise to power of} in deviation, and you have also changed the calculation in deviation - is this what you intended?