문제

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.

다른 팁

Your method is declared as cointToss, but you use coinToss.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top