Hi,
I am new to programming. The program I made reads a list of points from a text file. Then it finds the standard deviation and how many sets of points are in the file. Now I want to find the highest x value from the list and the highest y value from the list. So far I made the variables for these two values and I know I have to use an if statement.
Here is the code:
#include<stdio.h>
#include<math.h>
int main(int argc, char *argv[])
{
FILE *input;
float x, y, sumx, sumy, avex, avey, sumx_sqrd, sumy_sqrd, xmax, ymax;
int count;
if (argc == 1)
{
fprintf(stderr, "You must supply a file name.\n");
return 1;
}
input = fopen(argv[1], "r");
if (input == NULL)
{
fprintf(stderr, "Error opening file \"%s\".\n", argv[1]);
return 1;
}
sumx = 0.0;
sumy = 0.0;
sumx_sqrd = 0.0;
sumy_sqrd = 0.0;
count = 0;
while (fscanf(input, "%f\t%f", &x, &y) != EOF)
{
count++;
sumx += x;
sumy += y;
sumx_sqrd += x * x;
sumy_sqrd += y * y;
}
fclose(input);
avex = sumx/count;
avey = sumy/count;
printf("Average of x = %f\n", avex);
printf("Standard deviation of x = %f\n", sqrt(sumy_sqrd/count - avex * avex));
printf("\n");
printf("Average of y = %f\n", avey);
printf("Standard deviation of y = %f\n", sqrt(sumy_sqrd/count - avey * avey));
printf("\n");
printf("The maximum x value is %f\n", );
printf("The maximum y value is %f\n", );
printf("\n");
printf("The number of data sets is %d\n", count);
return 0;
}
Thank You