Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In statistics, the standard deviation measures the amount of variation or disper

ID: 3568099 • Letter: I

Question

In statistics, the standard deviation measures the amount of variation or dispersion from the average. It
can be calculated using the following formula:


Where sigma is the standard deviation, x is each value in the data set, mu is the mean of all values in the data
set, and n is the number of values in the data set. For your program you will ask the user for double values. Your program should stop when the user enters -99 when at this point your program will
display the mean and the standard deviation from the data set.

Sample output:
Enter a value (or -99 to quit): 3
Enter a value (or -99 to quit): 5
Enter a value (or -99 to quit): 11
Enter a value (or -99 to quit): 14
Enter a value (or -99 to quit): 11
Enter a value (or -99 to quit): -99
The average is 8.8 with a standard deviation of 4.11.

Using C++ code, not really sure what to do here.

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

int main(){
   int i;
   double sum = 0;
   vector<int> vect;
   while (i != -99){
       cout << "Enter a value (or -99 to quit):   ";
       cin >> i;
       if (i == -99)
           break;
       sum += i;
       vect.push_back(i);
   }
   double mean = sum/vect.size();
   sum = 0.0;
   for (int i = 0; i < vect.size(); i++){
       sum += (vect[i] - mean)*(vect[i] - mean);
   }
   sum = sum/vect.size();
   double sd = sqrt(sum);
   printf("%s %.1f %s %.2f ","The average is ",mean," with a standard deviation of ",sd);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote