The program calculates the standard deviation by having the user input the list of numbers into an array.
So i get these errors on the program
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'Nums' : unknown size
here is the code
#include <iostream>
#include <cmath>
using namespace std;
double std_Dev (double Nums[], int inSize, double &avg, double &sum, double &sum2);
int main ( ){
int inSize;
double avg = 0, sDev, sum = 0, sum2 = 0;
cout << "How many Numbers would you like to find the standard deviation for (max 100):";
cin >> inSize;
double Nums[inSize];
cout << "\nInput the numbers hit enter after each entry:";
for ( int i = 0; i < inSize; i++ ){
cin >> Nums[i];
}
sDev = std_Dev(Nums, inSize, avg, sum, sum2);
cout << sum<<" "<<inSize<<" "<<avg<<" "<<sDev<<endl;
return 0;
}
double std_Dev (double Nums[], int inSize, double &avg, double &sum, double &sum2){
for ( int i = 0; i < inSize; i++ ){
sum += Nums[i];
}
avg = sum / inSize;
for ( int i = 0; i < inSize; i++ ){
sum2 += pow( Nums[i] - avg, 2 );
}
double sDev;
sDev = sqrt( sum2 / ( inSize - 1 ) );
return sDev;
}
works in gcc but for some reason doesnt in VS 2005 which is what I need dumb class guidelines.