Array values , average and standard daviation

Hello, im still fearly new to C++ programming. In my Advance C++ class i was given the following assignment:
Write a program that will load real values from a file and compute their average. The values should be loaded and stored in array with a maximum capacity of 100 elements. Additionally, you should track the number of elements that were loaded (i.e. you need to be able to handle files containing less than the capacity and report an error if the file contains more elements than the array can store). After the loading the elements, you should iterate through the array and compute the average and standard deviation of the values stored in the array. Output the average and standard deviation.
I tried doing it, and gave out the following errors:
cout: undeclared identifier at line 25
endl: undeclared identifier at line 25
cout: undeclared identifier at line 27
endl: undeclared identifier at line 27
Can anyone help me?

// Assignment 2 One Dimensional Array.
//

#include <iostream>
#include <string>
#include <fstream>
#include "pch.h"

using namespace std;

int main()
{
const int SIZE = 4;

//Explicitly define the size of the array

double val[SIZE] = { 5.7, 8.0, 3.1, 10.1 };

double sum = 0; //Initalize the accumulator to 0

for (int i= 0; i < SIZE; i++)
sum += val[i];


cout << "The sum of array val is" << sum << endl;

cout << "The average of array values are" << sum / SIZE << endl;

return 0;

}

double computeMean(double vals[], int length) {
double mean = 0;
for (int i = 0; i < length; i++)
mean += vals[i];
mean /= length;
return mean;
}

double computeStandardDeviation(double vals[], int length, double mean) {
/*
double mean = 0;
for (int i = 0; i < length; i++)
mean += vals[i];
mean /= length;
return mean;
*/
}
Gave me no errors except for that mean was being redeclared at computeStandardDeviation(). Can you give the lines which you say are giving you an error?

To find the standard deviation:
Take the inputs values array, length of array of values, mean of values
Declare a variable for the sum of the differences.
Write a for-loop like you did with mean, then find the value - mean, then update the sum's value by adding to it.

You're left with file handling, but you haven't asked anything in particular.
Topic archived. No new replies allowed.