need help on writing standard deviation code

hi, i m working on a stardard deviation c++ code
my assignment is to find the std. dev. of " double x[] = {2,4,4,4,5,5,7,-9}; "
and i dont know why my instructor require us to put "double stddev(double arg[], int length)" this as the variable of the std dev
and here is what i have so far...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cmath>
   using namespace std;


   int main() {
      double x[] = {2,4,4,4,5,5,7,-9};
      double stddev(double arg[], int length);      
      double mean;
      double sum;
      double sum2;
     
   
      for ( int i = 0; i <=8; i++ )
      {
         sum += x[i];
      }
      mean=sum/8;
      
      for ( int i = 0; i <=8; i++ )
      {
         sum2 += pow((x[i]-mean),2);
      }
      stddev=sqrt(sum2/(7));
      cout << "S.D.: " << stddev(x,8) << endl;
      
      return 0;
   }


Hoping expert can help:>
Line 8: this is a function forward declaration
I believe that you are supposed to do something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
double stddev(double arg[], int length);

int main()
{
    double x[] = {2,4,4,4,5,5,7,-9}; //Length of 8
    double dev = stddev(x, 8);
    std::cout << "S.D.:" << dev << std::endl;
}

double stddev(double arg[], int length)
{
    /*Calculate standard deviation here and return the result*/
}

Topic archived. No new replies allowed.