In my C++ class we've been given an assignment to make a coin toss program that has the random number generator in one function and it is called into another function that runs it twelve(12) times.
int cointToss()
{
return rand()%2;
}
int run12()
{
int face, heads=0;
for (int i=0; i<12; i++)
{
face=coinToss();
if(face==1)
{
heads=heads+1;
}
}
return heads;
}
Whenever I try to run it however I keep getting this error, "1>source.obj : error LNK2001: unresolved external symbol "int __cdecl coinToss(void)" (?coinToss@@YAHXZ)"
I can't seem to find a resource saying how to correctly call the first function inside of the second.
Well, this is embarrassing.
You made a typo. The function is called "cointToss", but you are calling "coinToss" (see the extra t?).
C implicitly added a function declaration for you. Turn on warning, and you'll see.
Fix your typo, and the world will go round again.