identifier not found

I'm probably doing something incredibly stupid, but im getting these errors when i try to compile:

error C3861: 'functionThree': identifier not found
error C3861: 'functionTwo': identifier not found

any help would be much appreciated



#include <iostream>
using namespace std;


void functionOne(int value)
{
if ((value%2) == 0)
cout << "Function one result = " << value*3 << endl;
else
functionTwo(value);
}



void functionTwo(int value)
{
if ((value%2) == 0)
functionOne(value);
else
{
if ((value%3) == 0)
cout << "Function two result = " << value*2 << endl;
else
functionThree(value);
}
}




void functionThree(int value)
{
if ((value%2) == 0)
functionOne(value);
else
{
if ((value%3) == 0)
functionTwo(value);
else
cout << "Function three result = " << value*4 << endl;
}
}
int main ()
{
int value;
cout<<"Please enter a number\n";
cin>> value;
do
{
functionThree(value);
}while (value>0);

return 0;
system ("pause");
}
Then functionOne calls functionTwo but the name functionTwo was not yet declared.


void functionOne(int value)
{
if ((value%2) == 0)
cout << "Function one result = " << value*3 << endl;
else
functionTwo(value);
}

You shall place declarations of functionTwo and functionThree before using these names.
Last edited on
You need to declare function prototypes.

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

// declare function prototypes
void functionTwo(int value);
void functionThree(int value);

// ... rest of code follows here 
closed account (zb0S216C)
You're referencing "functionThree( )" and "functionTwo( )" before they are even declared. The compiler reads a file from top to bottom. In function "functionOne( )", "functionTwo( )" was called, but the compiler had not been informed that "functionTwo( )" had existed.

To resolve this, you need to inform the compiler that "functionTwo( )" and "functionThree( )" exist before using them. For instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void FunctionTwo( int Value_ );
void FunctionThree( int Value_ );

void FunctionOne( int Value_ )
{
    FunctionTwo( Value_ );
    FunctionThree( Value_ );
}

int main( )
{
    FunctionOne( 10 );
    return( 0 );
}

void FunctionTwo( int Value_ )
{
    // ...
}

void FunctionThree( int Value_ )
{
    // ...
}

Note the first 2 lines. These are called function prototypes. The tell the compiler that a function exists with the specified name, return type and parameters. Add prototypes for "functionTwo( )" and "functionThree( )" before "functionOne( )".

Wazzak
thanks for your help guys, as usual its so obvious when its shown to you!
Topic archived. No new replies allowed.