Help with array.

I'm trying to get the max,min,mean,std dev,variance of an array[200].. when I run the program it shows me no errors but my max, min etc are letters mixed with numbers.
this is my main.

#include<iostream>
#include<iomanip>
#include <cstdlib>
#include "Lib.h"
using namespace std;
int main()
{
double s[200];
int i;
for (i = 0; i < 200; i++)
{
s[i] = rand() % (1000 - 0 + 1) - 0;
}
cout << "200 values assigned to s" << endl
<< "Random numbers from 1-1000" << endl;
for (i = 0; i < 200; i++)
{
cout << setw(6) << i << setw(10) << s[i] << endl;
}
cout << "The maximum value of the array is" << endl;
cout << maxval << endl;
cout << "The minimum value of the array is" << endl;
cout << minval << endl;
cout << "The mean of the array is" << endl;
cout << mean << endl;
cout << "The variance of the array is" << endl;
cout << variance << endl;
cout << "The Standard deviation of the array is" << endl;
cout << std_dev << endl;
system("Pause");
return 0;

}


this are my functions

#include<cmath>
using namespace std;

double maxval(double s[], int n)
{
double maxvalue;
maxvalue = s[0];
for (int k = 1; k < n; k++)
{
if (s[k]> maxvalue)
maxvalue = s[k];
}
return maxvalue;
}
double minval(double s[], int n)
{
double minvalue;
minvalue = s[0];
for (int k = 1; k <= n; k++)
{
if (s[k] < minvalue)
minvalue = s[k];
}
return minvalue;
}
double mean(double s[], int n)
{
double sum(0);
for (int k = 0; k < n; ++k)
sum += s[k];
return sum / n;
}


double variance(double s[], int n)
{

double sum(0), mu;
mu = mean(s, n);
for (int k = 0; k<n; ++k)
{
sum += (s[k] - mu)*(s[k] - mu);
}
return sum / (n - 1);
}
double std_dev(double s[], int n)
{
return sqrt(variance(s, n));

}

and this is my header

double maxval(double s[], int n);
double minval(double s[], int n);
double mean(double s[], int n);
double std_dev(double s[], int n);
double variance(double s[], int n);

Last edited on
closed account (48T7M4Gy)
Use code tags <> please. Use the toolbox on the right.

Your code runs online after a bit of convenient editing of no consequence and produces output all numbers no letters. Show us the output you have.

BTW some of you functions need careful attention because the answers are wring. :)

200 values assigned to s
Random numbers from 1-1000
     0       897
     1       802
     2       765
     3       992
     4         1
     5       521
     6       220
     7       380
     8       729
     9       969
    10       184
    11       887
    12       104
    13       641
    14       909
    15       378
    16       724
    17       582
    18       387
    19       583
    20       241
    21       294
    22       159
    23       198
    24       653
    25       369
 etc etc etc
   196       565
   197       766
   198       466
   199       673
The maximum value of the array is
1
The minimum value of the array is
1
The mean of the array is
1
The variance of the array is
1
The Standard deviation of the array is
1
Topic archived. No new replies allowed.