Name your program file statscpp Do not use any global variab
Solution
Answer:
#include <iostream>
 #include <iomanip>
 #include <cmath>
using namespace std;
//Function prototypes
 int* histogram(int arr[], int length);
 double deviation(int arr[], int length);
 double mean(int arr[], int length);
int main() {
    int arr[100];
    int count=0;
    int temp;
    double sd;
    cout<<\"Enter the scores, enter -1 to stop\"<<endl;
    while(count<100)
    {
         cout<<\"Enter value \"<<count+1<<\": \";
         cin>>temp;
         if(temp == -1)
         {
             break;
         }
         else if(temp < 0)
         {
             cout<<\"You entered an invalid score.\";
             continue;
         }
         else
         {
             arr[count] = temp;
             count++;
         }
    }
    sd = deviation(arr, count);
    cout<<\"The standard deviation is:\"<<sd;
 }
//Since the question doesn\'t provide the format of the histogram function\'s output I am providing
 //the deviation an mean functions here
 double deviation(int arr[], int length)
 {
     double avg=0, sd=0;
     avg = mean(arr, length);
     for(int i=0; i<length; i++)
     {
         sd += pow((arr[i] - avg), 2);
     }
   
     sd = sqrt(sd/length);
     return sd;
 }
double mean(int arr[], int length)
 {
     double sum=0, mean=0;
     for(int i=0; i<length; i++)
     {
         sum += arr[i];
     }
     mean = sum/length;
     return mean;
 }
--------------------------------------------------------------------------------------------------------------------------
OUTPUT:
Enter the scores, enter -1 to stop.
Enter value 1:12
Enter value 2:21
Enter value 3:23
Enter value 4:32
Enter value 5:-1
The standard deviation is:7.10634


