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);
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:
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( )".