Mean and Standard Deviation to 100 numbers

Hello, Im a beginner at C++ and I have completely lost my mind to what my instructor is asking.

The question is to create a program that finds the mean and standard deviation of up to 100 numbers. I got the equation down (below) now I need to extend it...and that is where my brain shut down.

Can I have some help?







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

int main()
{
int x1, x2, x3, x4, x5;
int X1, X2, X3, X4, X5;
int x;
int s;

cout << " Enter 5 positive integers: ";
cin >> x1 >> x2 >> x3 >> x4 >> x5;
cout << endl;

x = (x1 + x2 + x3 + x4 + x5) / 5;
X1 = x1-x;
X2 = x2-x;
X3 = x3-x;
X4 = x4-x;
X5 = x5-x;
s = sqrt((pow(X1,2.0) + pow(X2,2.0) + pow(X3, 2.0) + pow(X4, 2.0) + pow(X5, 2.0))/5);

cout << " The mean average is " << x << endl;
cout << " The Standard deviation of the numbers is: " << s << endl;
return 0;
You want to ask the user how many numbers they want to enter, then write a loop that
iterates that many times. Inside the loop, ask the user to enter 1 number, read it,
and process it.
Oh. You will also want two integer arrays, rather than 200 numbered variables.

You'll also need some more for loops to compute x, all the Xs, and s. Find a pattern, and get back to us and we might help you some more. :)

-Albatross
Press ENTER twice to finish.
http://www.cplusplus.com/forum/beginner/2409/#msg9254

You don't need two arrays/vectors.
Just modify the vector in place with for (n...) v[n] -= x;

Next sum the squares (use your s variable, but make it a double instead of an int ... you'll need a for loop for this too) and get the sqrt() of the result...

Hope this helps.
Are you kidding me?!? ARRAYS are also evil? Hmm... I guess I can see why.

Though seriously, Duoas, c'mon. Arrays may be evil in that sense, but in most C++ classes, as far as I know, you learn how to use them before you learn how to use vectors. Wonder why, though, vectors are superior to arrays in almost all aspects.

Provided that the OP is willing to learn about vectors:

http://cplusplus.com/reference/stl/vector/

#include <vector>

vector<int> naem;

EDIT: I wonder why the professor gave two sets of variables if he didn't want both to be used...

-Albatross

Last edited on
What?

There's nothing wrong with arrays.
For an assignment asking for unbounded space, though, a vector is a better choice.

[edit]
Because a vector is an automatically-managed, dynamic array.
Last edited on
Topic archived. No new replies allowed.