Ok I got a little guidance from the TA in the class so it's better. But when I run it doesn't do anything. I honestly have no clue how to make this thing work and it's really driving my anxiety up the wall. See below for what I have. It was the TA's suggestion to use a for loop to get the max and min. I have to add range and standard deviation to the mess for part B of the assignment THEN write a linear regression program after this doing all of this same garble. Needless to say, I'm not very excited. I need like a legit tutor to show me how to apply the code, not just how to write it.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define NMAX 300
int main()
{
int data[NMAX], N=0; //array of data
float min=9999999.0, max=0.0; //max and min of data set
float sum = 0.0, avg, std_dev, range; //average, standard deviation, range of data set
FILE *fpin;
if((fpin = fopen("data.txt","r"))==(FILE*)NULL)
{
printf("File does not exist\n"); exit(-1);
}
for(N=0; fscanf(fpin, "%d", &data[N]) != EOF; N++);
{
for (N=0; data[N]>max; N++)
{
max = data[N];
}
for (N=0; data[N]<min; N++)
{
min = data[N];
}
for (N=0; data[N]; N++)
{
sum += data[N];
avg = sum / N;
}
}
fclose(fpin); // Close File after Reading
printf("The minimum value of this data set is %f.\n", min);
printf("The maximum value of this data set is %f.\n", max);
printf("The average value of this data set is %f.\n", avg);
return 0;
}