Problem with C++ on XCode

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!


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

//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];}

for (int j=0; j < N; ++j)
{sumx = sumx + xdata [j];}

for (int k=0; k < N; ++k)
{sumy = sumy + ydata [k];}

for (int l=0; l < N; ++l)
{xsquared = xsquared + pow(xdata[l],2);}

for (int m=0; m < N; ++m)
{sumx = sumx + xdata [m];
sumxsquared = pow(sumx,2);}

slope = (xy - (1/N)*sumx*sumy) / (xsquared - (1/N)*sumxsquared);
rcoef[0] = slope;

yintercept = ydata[1] - xdata[1]*slope;
rcoef[1] = yintercept;

rsquared = frsquared (xdata [] , ydata [], N, rcoef[2]);
}


// The below function calculates rsquared
float frsquared (float xdata[], float ydata [], int N, float rcoef[2])
{
float xmean, ymean, top, bottom, bottom2, ysquared=0, sumysquared=0, xy=0, sumx=0, sumy=0, xsquared=0, sumxsquared=0;
xmean = fmean (xdata [], N);
ymean = fmean (ydata [], N);

for (int i=0; i < N; ++i)
{xy = xy + xdata(i) * ydata(i);}

for (int i=0; i < N; ++i)
{sumx = sumx + xdata [i];}

for (int i=0; i < N; ++i)
{sumy = sumy + ydata [i];}

for ( int i=0; i < N; ++i)
{xsquared = xsquared + pow(xdata[i],2);}

for (int i=0; i < N; ++i)
{sumx = sumx + xdata [i];
sumxsquared = pow(sumx,2);}

for ( int i=0; i < N; ++i)
{ysquared = ysquared + pow(ydata[i],2);}

for (int i=0; i < N; ++i)
{sumy = sumy + ydata [i];
sumysquared = pow(sumy,2);}

top = N*xy-sumx*sumy;
bottom = (N*xsquared - sumxsquared)* (N*ysquared - sumysquared);;
bottom2 = pow(bottom,0.5);
frsquared = top/bottom;
return frsquared;
}

//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);
}
}


Last edited on
I would add the .cpp file or screenshots but cannot seem to find the button to do so...
Topic archived. No new replies allowed.