hi? i was trying out this program, could someone please check this program and explain how the output generates the 10 numbers ..are these numbers stored in the compiler memory, and where did the -1.#J come from and what does it mean..
Also, could you check if the code style is adequate, if not can you suggest any improvements.
Thanks
cheers,
SAAB
#include <iostream.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>//what is this used for
#include<math.h>
const int size=10;
void fillArray(int array[size]);
void displayArr_element(int array[size]);
int main()
{
double value = 0.0;
int number = 0;
double sum = 0.0;
double sumOfSquares = 0.0;
double mean = 0.0;
double standardDeviation = 0.0;
int array[size];
int element=0;
int index=0;
fillArray(array);
displayArr_element(array);
cout << "This program will calculate the mean and standard deviation\n"<< "of a series of values that you enter." << endl;
if (standardDeviation == -1)
cout<<" the element"<<element<<" not found"<<endl;
else
cout<<" the element is :"<<element<<" was found at:"
<<"index["<<standardDeviation <<"] of the array."<<endl;
//CALCULATE MEAN AND STANDARD DEVIATION
mean = sum / number;
standardDeviation = sqrt(sumOfSquares / number - mean * mean);
cout.setf(ios::fixed);
cout.precision(2);
cout << "\nThe mean is: " << mean << endl;
cout << "The standard deviation is: " << standardDeviation <<endl;
cout<<" the element is :"<<element<<" was found at:"
<<"index["<<standardDeviation <<"] of the array."<<endl;
return 0;
}
void fillArray(int array[size])
{
srand(time(0));
for(int i=0; i<size; ++i) array[i]=rand()%100;
}
void displayArr_element(int array[size])
{
cout<<"After sequencial Search the array Element with index is:"<<endl;
for(int i=0; i<size; ++i)
cout<<array[i]<<endl;
}