Error: Identifier not found

Below example throws a error saying "Identifier not found" even when both the functions are defined above main because "even" is not visible from "odd" method.

Therefore it is a good practice to declare all the methods above the main and define the methods below the main. For the code to work uncomment the commented lines and move the 'odd' and 'even' methods below the main().


#include
using namespace std;

//void odd (int a);
//void even (int a);

void odd (int a)
{
if ((a%2)!=0) cout << "Number is odd.\n";
else even (a);
}

void even (int a)
{
if ((a%2)==0) cout << "Number is even.\n";
else odd (a);
}

int main ()
{
int i;
do {
cout << "Type a number (0 to exit): ";
cin >> i;
odd (i);
} while (i!=0);
return 0;

Comments

Popular posts from this blog

Network Security: LAN manager authentication level

Cisco AnyConnect Secure Mobility Client - VPN service not available. The VPN agent service is not responding