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.
#include <iostream>
#include <cmath>
usingnamespace 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 = newint [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;
}
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
#include <iostream>
#include <cmath>
usingnamespace 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 = newint [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));
}}