LINKER ERROR VISUAL STUDIO 2010

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>

using namespace std;

void countx(double, int[]);
void initializeArray(int[]);
void printResult(double,double,int,int[]);

void main()


{

int i, count,distF[8];
double x,sum1,sum2;

/* Calculation for X~ (x,0,1) */

srand(time(NULL));
count=0;
sum1=sum2=0.0;
initializeArray(distF);

for(i=1;i<10000;i++)
{

x=(double)(rand())/RAND_MAX;
if(x>.9 && x<= 1.8)
count++;
countx(x,distF);
sum1 += x;
sum2 += x*x;

}

cout<<"Results for uniform Distribution:\n";
printResult(sum1,sum2,count,distF);

srand(time(NULL));
count=0;
sum1=sum2=0.0;
initializeArray(distF);

for(i=1;i<=10000;i++)
{
x= -(log(1-(double) (rand())/RAND_MAX))/2;
if(x>.9 && x<=1.8)

countx(x,distF);
sum1+=x;
sum2+=x*x;

}


cout<<"Reuslts for exponential Distribution 2:\n";
printResult(sum1,sum2,count,distF);

/*** Calculations for P(x=1/2)=1 ***/
srand(time(NULL));
count=0;
sum1=sum2=0.0;
initializeArray(distF);

for(i=1;i<=1000;i++)
{
x=.5;
count++;
countx(x,distF);
sum1+=x;
sum2+=x*x;

}

cout<<"Reuslts for exponential Distribution 3:\n";
printResult(sum1,sum2,count,distF);

srand(time(NULL));
count=0;
sum1=sum2=0.0;
initializeArray(distF);
double temp;

for(i=1;i<=10000;i++)
{
temp=(double)(rand())/RAND_MAX;
if(temp<=.5)
x=.25;
else
x=1.50;
if(x>.9 && x<=1.8)
count++;
countx(x,distF);
sum1 += x;
sum2 +=x*x;
}

cout<<"Reuslts for Distribution #4:\n";
printResult(sum1,sum2,count,distF);

/*Function*/

void countx(double x, int distF[]);
{
int j=0;
double t= -0.25;
do
{
if(x<=t)
{
for(int k=j;k<8;k++)
distF[k]++;
break;
}
t += .25;
j++;
}
while(t<=1.50);
//return;
}

void intializeArray(int distF[]);
{
for(int j=0;j<8;j++)
distF[j]=0;
//return;
}


void printResult(double sum1, double sum2, int count, int distF[]);
{
double ev_x,var_x,pr_x;
ev_x=sum1/10000;
var_x=sum2/10000-(ev_x * ev_x);
pr_x=(double)(count)/10000;

cout<<"Expected value: " <<ev_x<<endl;
cout<<"Variance: "<<var_x<<endl;
cout<<"P(0.9<x<=1.8):" <<pr_x<<endl;

cout<<"t=";
for(int k=-1; k<7;k++)
cout<<.25 *k<<"\t";
cout<<"lnFx(t)=";
for(int j=0;j<8;j++)
cout<<(double)(distF[j])/10000<<"\t";
cout<<endl;
//return;
}

}



Need help!

>kikii.obj : error LNK2019: unresolved external symbol "void __cdecl printResult(double,double,int,int * const)" (?printResult@@YAXNNHQAH@Z) referenced in function _main
1>kikii.obj : error LNK2019: unresolved external symbol "void __cdecl countx(double,int * const)" (?countx@@YAXNQAH@Z) referenced in function _main
1>kikii.obj : error LNK2019: unresolved external symbol "void __cdecl initializeArray(int * const)" (?initializeArray@@YAXQAH@Z) referenced in function _main
Try placing the functions above the main, without using forward declarations.
void main()

Should be:

int main()

@pogrady

I wouldn't have thought that would make any difference.

@krazyman

Please edit your post to use code tags - the <> button on the right Make sure you always do this.

There will be probably be other things to comment on, once you do this.

Edit:

Is all the code in one file?
Last edited on
1
2
void printResult(double sum1, double sum2, int count, int distF[]);
{


Use code tags. Look for the <> button.

After the ) do you see the semi-colon that shouldn't be there? It's present in all of your function definitions.

I can't tell just by looking due to the lousy formatting, but it appears all of your function definitions are inside the body of main, which won't work.
Good work cire.

@OP
If you format your braces like this, then you might not be tempted to put in a semicolon:

1
2
3
int MyFunction ( int arg) {
//your code
}


The same idea works well for loops and if statements etc.

HTH

Edit: If you use an IDE, it should display your code as an error in some way - red font or squiggly red underlining say.
Last edited on
Topic archived. No new replies allowed.