
/*
 *  L7 assigns 1000 numbers chosen randomly from 
 *  a range between 1 & 10000 to the x array.
 *  It then prints the sum of all numbers, all numbers 
 *  greater than 8000, all numbers less than 100,
 *  and the standard deviation.
 */

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <math.h> 
using namespace std;
/* The inclusion of math.h allows for the use of functions that 
 * are specific to the math library such as sqrt() and pow().
 * We will cover in greater detail in later lectures.  In the interim, please 
 * google for more information.
 */


int main() {
  srand(time(NULL));
  const int MAX = 1000;
  int x[MAX];
  long int sum = 0;
  float mean = 0;
  float sqrsum = 0;

  for (int i = 0; i < MAX; i++) {
    x[i] = rand()%10000 + 1;
    sum += x[i];
  }
  cout << "\nsum: " << sum << "\n";

  for (int i = 0; i < MAX; i++) {
    if (x[i] > 8000) 
      cout << "> 8000: " << x[i] << "\n";
  }

  for (int i = 0; i < MAX; i++) {
    if (x[i] < 100) 
      cout << "< 100: " << x[i] << "\n";
  }

  //standard deviation
  mean = sum/(float)MAX;
  for (int i = 0; i < MAX; i++) {
    sqrsum += (pow((x[i] - mean),2));
  }
  cout << "stddev: " << sqrt(sqrsum/MAX) << endl;
  
  return 0;
}

