Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // project6
  4. //
  5. // Created by . on 10/21/12.
  6. // Copyright (c) 2012 baldurt. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <cmath>
  11. using namespace std;
  12. const int num=0, i=0;
  13. double stdDev(double s[], int size);
  14.  
  15. double average(double s[], int size);
  16. int main()
  17. {
  18. double array[i];
  19. double stdDeviation;
  20. char ans;
  21. int num;
  22.  
  23. do
  24. {
  25. cout << "Enter desired amount of numbers/n";
  26. cin >> num;
  27.  
  28. for (int i = 0; i < num; i++){
  29. cin >> array[i];
  30. }
  31.  
  32. cout << "Enter values, separated by white space" << endl;
  33.  
  34. for(int i = 0; i < array[i]; i++){
  35. cin >> [i]
  36. stdDeviation = stdDev(array[i]);
  37. cout << "The Standard Deviation is: "
  38. << stdDeviation << endl;
  39. cout << "Do you want to continue (Y/N)?\n";
  40. cin >> ans;
  41.  
  42. } while(ans == 'y' || ans == 'Y');
  43.  
  44. return 0;
  45.  
  46.  
  47. double stdDev(double s[], int size)
  48. {
  49. double sumSquares = 0;
  50. double avg = average(s, size);
  51.  
  52. for(int i = 0; i < size; i++)
  53. sumSquares += (s[i] - avg) * (s[i] - avg);
  54.  
  55. return sqrt(sumSquares / size);
  56.  
  57.  
  58. double average(double s[], int size)
  59. {
  60. double sum = 0;
  61.  
  62. for(int i = 0; i < size; i++)
  63. sum += s[i];
  64. }
  65. return sum / size;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement