I am trying to extend this piece of code I have written by also working out the range of the 6 numbers entered, unfortunately I don't really know where to start other then knowing I need if/else statements. Also, what if the user inputs a negative number?
const size_t N = 6;
float X[N] {}; // X is an array of N float values
float value;
size_t x = 0;
while ( x < N && std::cin >> value ) // x can get values 0, 1, 2, 3, 4, 5
{
X[x] = value;
++x;
}
// x is now the number of input values. 0 <= x <= N
float sum = 0.0f; // We have seen 0 values yet, so their sum is 0.
for ( size_t y = 0; y < x; ++y )
{
sum += X[y];
}
float mean = 0.0f; // Some dummy default in case we had no input.
if ( 0 < x )
{
mean = sum / x;
}
Calculating StandardDeviation is obviously yet another loop.