Standard Deviation and RMS

Hello Everyone,
Is my equations for standard deviation and rms incorrect in this code? Im not getting the correct output and i dont understand why.

#include <iostream>
#include <cmath>
using namespace std;

int main ()
{
int N;

int sum = 0.0;
int minimum = 999.999;
int maximum = -999.999;
int stDev = 0.0;

double mean;
double range;
double rms;

cout << "Set the size of the array: ";
cin >> N;
cout << endl;

float array[N];

cout << "Enter in integers: " << N << endl;

for(int i = 0; i < N; i++)

{
int x;
cin >> x;
array[i] = x;
}

cout << endl;

for(int i = 0; i <= N; i++)

{
sum += array[i];

if (array[i] > maximum)
maximum = array[i];
if (array[i] < minimum)
minimum = array[i];

double y;
y = pow(array[i],2);
rms = sqrt(y / N);

double z;
z += pow((array[i] - mean),2);
double variance;
variance += (z / (N-1));
stDev = sqrt(variance);

}

mean = sum/N;

range = maximum - minimum;

cout << "The Mean: " << mean << endl;
cout << "The Maximum: " << maximum << endl;
cout << "The Minimum: " << minimum << endl;
cout << "The Range: " << range << endl;
cout << "The Root-Mean-Square: " << rms << endl;
cout << "The Standard Deviation: " << stDev << endl;

return 0;
}
Last edited on
Topic archived. No new replies allowed.