Random Number Output of MEan and SD

I thought I had this code correct for the most part, I get an error at the main. The code is supposed to allow users to input an array size from that size random numbers will be generated for the array. Using those number the mean and standard deviation should be the output. Not sure how to fix.

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  #include <iostream>
#include <cmath>
using namespace std;

void calculateSD(int array[]);
void Calcmean(int array[])

int main( )
{ 

  int size=0;
  cout<<endl;
  cout<<" Please Enter Size of Array= ";
  cin>>size;

  int *array = new int [size]; // declaration of the dynamic array 

  srand(time(NULL));
  //cout<<endl;

   for (int i =1; i<=size; i++){ //the provides the counter for the number random number generation
	int number = 1+rand()%50; // genrate random values in the range of 1-50
	array[i-1] = number; 

  cout<<" Mean = "<<Calcmean(array)<<endl;
  cout<<" Standard Deviation = "<<calculateSD(array)<<endl;
   }
   
void Calcmean(int array[])

 for(int i = 0; i < size; ++i)
     
    {
       //double sum;
       sum += array[i];
    }
    double mean;
    double sum;
    
    sum += array[i];
    
    mean = sum/size;
    cout<<"Mean = "<<mean<<endl;
    
    return (mean);
    
    delete [] array;
}

void calculateSD(int array[])
  
double standardDeviation;
    for(i = 0; i < size; ++i){
    
        standardDeviation += pow(array[i] - Calcmean(array), 2); // raised to the power of 2

    return (standardDeviation/(size));

    delete [] array;
}
Hi,

I have debugged the code upto compilation state and have mentioned the errors in code, now you can debug it further so that you can learn something too... Hope it helps

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  #include <iostream>
#include <cmath>
using namespace std;
int size=0;//making size global
double calculateSD(int array[]);//needed a return type
double Calcmean(int array[]);

int main( )
{ 

  
  cout<<endl;
  cout<<" Please Enter Size of Array= ";
  cin>>size;

  int *array = new int [size]; // declaration of the dynamic array 

  srand(time(NULL));
  //cout<<endl;

   for (int i =1; i<=size; i++){ //the provides the counter for the number random number generation
	int number = 1+rand()%50; // genrate random values in the range of 1-50
	array[i-1] = number; 

  cout<<" Mean = "<<Calcmean(array)<<endl;
  cout<<" Standard Deviation = "<<calculateSD(array)<<endl;
   }
   return 0;
}//<- this wasnt present here before 
double Calcmean(int array[])
{ double sum;
 for(int i = 0; i < size; ++i)
     
    
      
       sum += array[i];
    
    double mean;
   
    
    
    mean = sum/size;
    cout<<"Mean = "<<mean<<endl;
    
    return (mean);
    //nothing executes after return
   
}

double calculateSD(int array[])
  {
double standardDeviation;
    for(int i = 0; i < size; ++i){
    
        standardDeviation += pow(array[i] - Calcmean(array), 2); // raised to the power of 2

    return (standardDeviation/(size));

    
}}


PS: If you still have doubts feel free to ask
Thank you, got it
Topic archived. No new replies allowed.