## Joshua_9

how would i make a program that outputs this:
amount of vairiables: 3
3123
1412
2412
mean: 1414
standard viariance: 4344

## L7Sqr 227

Outputting exactly that is an easy exercize - simply execute a number of `std::cout` statements.

I think what you mean to ask is how to do the following:

• Read a value (as an integral value)
• Read that many more values (as integral or floating point)
• Compute functions over the set of values you read

Those are the broken down pieces of your problem. What items have you tried? Which are you having problems with?

## Moschops 683

The mean of the numbers 3123, 1412 and 2412 is 2316 (not 1414), and the variance of them is also not what you stated.

Are you using some alternative definition of these terms?

## Joshua_9

can u give me a random example anyway

## ddanbe 2,724

If you would show us your code on how you did the mean calculation, that would help us alot to provide you an answer to your question.

## Joshua_9

``````#include<iostream>
#include<math.h>
using namespace std;

float find_mean (float num1, float num2, float num3, float num4, float num5, float num6, float num7, float num8, float num9, float num10, float num0 )
{
return (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 + num10 + num0 )/11;
}
int main()
{
float a, b, c, d, e, f, g, h, i, j, k;
cout << "Enter eleven numbers." << endl;
cin >> a >> b >> c >> d >> e >> f >> g >> h >> i >> j >> k;
cout << " Mean: " << find_mean(a, b, c, d, e, f, g, h, i, j, k) << endl;
}
``````

## David W 131

You might like to look here to find an example of taking in numbers ... (into an array)

and finding the sum and average values ...

http://developers-heaven.net/forum/index.php/topic,2019.0.htm

You will probably want to take in a variable number of values ... so an easy student way to start to do that, is to use an array with the max size prefixed at compile time, as in the following example ... (make sure that the array size is big enough to handle ALL the expected values)

(later you could use an easily expandable container like the STL vector container)

``````// arrayInt.cpp

// enters integer data, finds sum, average ...

// http://developers-heaven.net/forum/index.php/topic,46.0.html

#include <iostream>

using namespace std;

int const MAX_SIZE = 4; // using a small size here for easier testing ...

int getValidInt( const char prompt[] )
{
for( ; ; ) // an example of a C/C++ forever loop ... until 'return'
{
cout << prompt << flush;
int testInt;
cin >> testInt;
if( cin.good() )
{
cin.sync(); // 'flush' cin stream as we go ...
return testInt;
}
// else ...
cin.clear(); // clear cin error flag(s) ...
cin.sync();
cout << "Invalid input! Integers only please ...\n" ;
}
}

bool more()// defaults to 'true'/'yes' ... unless 'n' or 'N' entered
{
cout << "More (y/n) ? " << flush;
cin.sync(); // 'flush' cin stream ...
// else ...
return true;
}

int sumAry( const int ary[], int size )
{
int sum = 0;
for( int i = size-1; i >= 0; --i ) sum += ary[i];
return sum;
}

void showAry( const int ary[], int size )
{
for( int i = 0; i < size; ++i ) cout << ary[i] << " ";
}

int main()
{
int my_ary[ MAX_SIZE ]; // create array to hold upto MAX_SIZE int's
int i = 0;
do
{
my_ary[ i ] = getValidInt( "Enter next integer to sum: " );
++ i;
if( i == MAX_SIZE )
{
cout << "You have reached the maximum " << MAX_SIZE
<< " number of elements.\n";
break;
}
}
while( more() ); // make sure cin stream is 'empty' before calling more()

cout << "\nShowing the entered array: ";
showAry( my_ary, i );

int sum = sumAry( my_ary, i );
cout << "\nFor the " << i << " numbers entered, the sum was " << sum
<< " and the average was " << double(sum)/i << endl;

cout << "\nPress 'Enter' to continue/exit ... " << flush;
cin.get(); // keep 'Window' open until 'Enter' key is pressed ...
}
``````

## David W 131

Oops ... duplicate deleted