Eray
Eray

Reputation: 7128

C++ Functions and 'identifier not found' error

I'm a C++ learner.I'm trying to code a basic C++ project. It's basic automation system . It has a navigation menu.

Choose an option :
   1 ) Add a new customer
   2 ) List all customers
   ...

There will be a navvariable, which containing user's choice. This is my source code :

#include <stdio.h>
#include <clocale>

int nav;    

void main()
{
    setlocale(LC_ALL,"turkish");
    navigasyon();
    switch (nav) // checking 'nav' variable which assigned in navigasyon()
    case "1" :
         printf("Now you are adding a new customer");
    break;
    case "2" :
         printf("Now you are listing all customers");
    break;
}

void navigasyon()
{
    printf("Choose an option \n");
printf("1 ) Add a new customer\n");
printf("2 ) List all customers\n");

scanf("%d", &nav); // assigning '`nav' variable
}

In shortly, in main() , navigasyon() will show navigation menu, user choose 1 or 2 and then navigasyon() assinging it to nav . Lastly checking navwith switch-case.

But i'm getting 'navigasyon': identifier not found error.

Upvotes: 1

Views: 20469

Answers (6)

Mike S.
Mike S.

Reputation: 2111

You need to declare the function first

After your #includes statements write this

void navigasyon();

Alternatively you can place the function before the main. In C++ a function has to be declared before being used, unless it's placed before the main.

Upvotes: 3

m42e
m42e

Reputation: 148

you need to declare the method before using it. Add the following Line before your main:

static void navigasyon();

This declares navigasyon as a local only (static) function. For further use you should move the decleration to a .h file, remove the static and of course include this .h file.

Upvotes: 1

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81684

You need a declaration for the navigasyon() function at the beginning of your file, so the compiler knows about it when it compiles main():

void navigasyon();

Upvotes: 2

Christian Horsdal
Christian Horsdal

Reputation: 4932

Place 'navigasyon' above main.

C++ demands that functions are declared before they are used. This can done by placing the whole function before the usage or by forward declaration, where you only have the signature before.

Upvotes: 2

n0rd
n0rd

Reputation: 12610

You use navigasyon function in main before defining it. You need either to switch places of main and navigasyon, or declare navigasyon before main.

Upvotes: 3

kol
kol

Reputation: 28688

You should declare navigasyon before main.

Upvotes: 8

Related Questions