Hey guys,
I am very new to programming and am taking a beginners class in college right now. I have to solve for the mean, linear regression line, and variance. I am given a txt file that has two columns. The first (x-column) is height and the second (y-column) is wingspan. Long story short, I have to write a code that has 4 seperate functions and will take the txt file. I keep getting parse issues saying expected expression. I have no idea what that means and cannot figure out my error. Here is my code below If someone can help me on this, that would be great.
Thanks!
//The below function calculates the mean
float fmean (float data [], int N)
{
float fmean;
float sum=0;
for (int i =0; i < N; ++i)
{
sum = data[i] + sum;
}
fmean = sum/N;
return fmean;
}
// The below function calculates the line of best fit
void flinfit (float xdata [], float ydata[], int N, float rcoef[2])
{
float slope, yintercept, xmean, ymean, rsquared, xy=0, sumx=0, sumy=0, xsquared=0, sumxsquared=0;
xmean = fmean (data [], N);
ymean = fmean (data [], N);
int h, l, j, k, m;
for (int h=0; h < N; ++h)
{xy = xy + xdata[h]*ydata[h];}
//Main Function Calculation
int main (void)
{
static float xdata[100], ydata [100], xmean, ymean, linfit, rsquared;
static int i, N;
char infile[100], outfile [100];
FILE *inputfile, *outputfile;;
printf("Enter the file name\n");
scanf("%s",infile);
inputfile = fopen (infile, "r");
if (inputfile ==NULL)
{printf ("The file does not exist!!\n");
exit (EXIT_FAILURE);
}
else
{
printf ("Enter the number of data points in the inputfile \n");
scanf ("%s", outfile);
inputfile = fopen(outfile,"r");
printf ("Enter the total number of data points collected\n");
scanf ("%i", &N);
for (i; i<N; ++i)
{
fscanf(inputfile, "%f %f", &xdata[i], &ydata[i]);;
}
xmean = fmean (data[], N);
ymean = fmean (data[], N);
linfit = flinfit( xdata [], ydata[], int N, float rcoef[2]);
rsquared = frsquared (xdata[], ydata [], N, rcoef[2])
printf("Enter output file name\n")
scanf("%s",outfile)
outputfile = fopen(outfile, "w")
fprintf (outputfile, "The mean height is %3.4f cm and mean wingspan is %3.4f\n The linfit is %3.4f cm^2\n Finally, the rsquared value is %3.4f", xmean, ymean, linfit, rsquared);
}
}