Hi. i am taking a C++ intro course and one of my projects is to create a program that will give me the beta 0 and beta 1 of a regression. The user must input a the following: how many data sets?, each of the Xs and each of the Ys. the following is what I have gotten so far with a little help from people in my class. we are all having major problems with this project. here is wat i have so far.
int i;
void getb1(double X[], double Y[], int size, double &b1)
{
double sumY = 0.0;
double sumX = 0.0;
double sumXY = 0.0;
double b1; //this is where the third error is
double sqrX = 0.0;
for (i=0; i<size; i++)
{
sumXY = sumXY + X[i]*Y[i];
sumX = X + X[i]; //this is where the fourth error is
sumY = Y + Y[i]; //this is where the fifth error is
sqrX = sqrX + X[i]*X[i];
}
b1 = (size*sumXY-sumX*sumY)/(size*sqrX-sumX*sumX);
}
void getb0(double X[], double Y[], double b1, int size, double &b0)
{
double sumX = 0.0;
double Xbar = 0.0;
double Ybar = 0.0;
double sumY = 0.0;
for (i = 0; i < size; i++)
{
sumX = sumX + X[i];
sumY = sumY + Y[i];
}
Xbar = sumX/size;
Ybar = sumY/size;
}
#include <iostream>
#include <string>
using namespace std;
void getb1 (double X[], double Y[], int size, double &b1);
void getb0 (double X[], double Y[], int size, double &bo);
int main ()
{
int size;
double X[] = {0};
double Y[] = {0};
double b1;
double b0;
cout << "Please give me the size of your variables." << endl;
cin >> size;
cout << "Now start to input your x variables" << endl;
for (i = 0; i < size; i++){
cin >> X[i];
}
cout << "Now start to input your Y variables." << endl;
for (i = 0; i < size; i++){
cin >> Y[i];
}
getb1 (X[], Y[], size, b1); //this is where the first error is
getb0 (X[], Y[], size, b1, b0); //this is where the second error is
cout << "Now you have the model." << endl;
cout << "Y = " << b1 << "X" << "+" << b0 << endl;
return 0;
}
these are the errors i get when i build the program as it is (th errors are listed in the program above):
error C2059: syntax error : ']'
error C2059: syntax error : ']'
error C2082: redefinition of formal parameter 'b1'
error C2111: '+' : pointer addition requires integral operand
error C2111: '+' : pointer addition requires integral operand
i have a feeling that there are major problems in this program other than the ones listed, but i just cant figure it out.
also please note that i am quite new to all this so i don't understand all the terminology. I just wrote this program according to the my class slides, which are not very helpful.
thanks in advance for all the help.