Hi I'm a new user of c++ and our professor gave us a homework problem where we have to find the standrad deviation, the min, the max and the avg of an array of numbers, here is what I have so far but now I'm really stuck trying to make the algorithm work for the min and max and avg.

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

double mma (double Nums[], int inSize, double max[], double min[]);

double std_Dev ( double Nums[], int inSize );

double avg = 0, sDev, sum = 0, sum2 = 0;

int main ( ){
	int inSize;
    double Nums[100];

	cout << "How many Numbers would you like to work with (max 100):";
	cin >> inSize;

	cout << "\nInput the numbers hit enter after each entry:";
	for ( int i = 0; i < inSize; i++ ){
		cin >> Nums[i];
	}

	sDev = std_Dev ( Nums, inSize );
	mma ( Nums, inSize );

	cout <<"The max, the min and the average is"<<
    cout << "The Standard deviation is "<< sDev<<endl;
	

	return 0;
}

double mma (double Nums[], int inSize, double max[], double min[]){
    for ( int i = 0; i < inSize; i++ ){
        if (inSize>max[i]){max[i]=inSize;}
        if (inSize<min[i]){min[i]=inSize;}
    	sum += Nums[i];
	    }
    avg = sum / inSize;
    
}
    
double std_Dev ( double Nums[], int inSize ){
	for ( int i = 0; i < inSize; i++ ){
		sum += Nums[i];
	}
    avg = sum / inSize;

	for ( int i = 0; i < inSize; i++ ){
		sum2 += pow( Nums[i] - avg, 2 );
	}

	sDev = sqrt( sum2 / ( inSize - 1 ) );

	return sDev;
}

Thank you for all your help!

Code tags:

[code]

// paste code here

[/code]

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

double mma (double Nums[], int inSize, double max[], double min[]);

double std_Dev ( double Nums[], int inSize );

double avg = 0, sDev, sum = 0, sum2 = 0;

int main ( ){
int inSize;
double Nums[100];

cout << "How many Numbers would you like to work with (max 100):";
cin >> inSize;

cout << "\nInput the numbers hit enter after each entry:";
for ( int i = 0; i < inSize; i++ ){
cin >> Nums[i];
}

sDev = std_Dev ( Nums, inSize );
mma ( Nums, inSize );

cout <<"The max, the min and the average is"<<
cout << "The Standard deviation is "<< sDev<<endl;


return 0;
}

double mma (double Nums[], int inSize, double max[], double min[]){
for ( int i = 0; i < inSize; i++ ){
if (inSize>max[i]){max[i]=inSize;}
if (inSize<min[i]){min[i]=inSize;}
sum += Nums[i];
}
avg = sum / inSize;

}

double std_Dev ( double Nums[], int inSize ){
for ( int i = 0; i < inSize; i++ ){
sum += Nums[i];
}
avg = sum / inSize;

for ( int i = 0; i < inSize; i++ ){
sum2 += pow( Nums[i] - avg, 2 );
}

sDev = sqrt( sum2 / ( inSize - 1 ) );

return sDev;
}

Here's your code in code tags, but you either didn't format it or the formatting got stripped. Here it is formatted. As you can see, it's much easier to read:

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

double mma(double Nums[], int inSize, double max[], double min[]);

double std_Dev(double Nums[], int inSize);

double avg = 0, sDev, sum = 0, sum2 = 0;

int main()
{
  int inSize;
  double Nums[100];

  cout << "How many Numbers would you like to work with (max 100):";
  cin >> inSize;

  cout << "\nInput the numbers hit enter after each entry:";
  for (int i = 0; i < inSize; i++)
  {
    cin >> Nums[i];
  }

  sDev = std_Dev(Nums, inSize);
  mma(Nums, inSize);

  cout << "The max, the min and the average is" << cout << 
    "The Standard deviation is " << sDev << endl;


  return 0;
}

double mma(double Nums[], int inSize, double max[], double min[])
{
  for (int i = 0; i < inSize; i++)
  {
    if (inSize > max[i])
    {
      max[i] = inSize;
    }
    if (inSize < min[i])
    {
      min[i] = inSize;
    }
    sum += Nums[i];
  }
  avg = sum / inSize;

}

double std_Dev(double Nums[], int inSize)
{
  for (int i = 0; i < inSize; i++)
  {
    sum += Nums[i];
  }
  avg = sum / inSize;

  for (int i = 0; i < inSize; i++)
  {
    sum2 += pow(Nums[i] - avg, 2);
  }

  sDev = sqrt(sum2 / (inSize - 1));

  return sDev;
}

What exactly is the problem? We need more details. Does it compile? Does it run? Does it give the wrong answers? What is the input? What is the correct output for that input? What is the actual output?

One thing that caught my eye is line 26: mma(Nums, inSize); You're calling the function 'mma' with two arguments, but in your function definition you say: double mma(double Nums[], int inSize, double max[], double min[]); which are 4 arguments. Also you say that the function should return a 'double', but it never does. (perhaps you want a 'void' function?)

Very sorry but I couldn't get the source of the problem. Did you compile it? did you run it? whare does the problem lie?

Very sorry but I couldn't get the source of the problem. Did you compile it? did you run it? whare does the problem lie?

The post above your post, specifies exactly where the problem lies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.