I am new to coding and need to know how to display the Max, Min, Avg, and the new normalized values of my array. I have the max min and avg working correctly as of now, but am very confused on how i would have my function display the proper new values of the array. The point is to use the function; xi'=(xi-min)/(max-min) My current code is the following:
#include <iostream>
using namespace std;
void normalizeMinMaxAvg(double data[], int size,double& min, double& max, double& avg)
{
max = 0;
min = 0;
int sum = 0;
int i;
avg = 0;
for (i = 0; i < size; i++) {
sum += data[i];
if ( max < data[i]) {
max = data[i];
}
if (min > data[i]) {
min = data[i];
}
}
avg = sum/size;
for (i = 0; i < size; i++){
data[i] = (data[i]-min)/(max-min);
}
}
int main()
{
double data[] = {-10.0,0.0,20.0,30.0,500.0};
double min, max, avg;
normalizeMinMaxAvg (data, 5, min, max, avg);
cout << "min = " << min << "\n";
cout << "max = " << max << "\n";
cout << "avg = " << avg << "\n";
cout << data;
return 0;
}
std::arrayorstd::vectorinstead.minandmaxare the same?