# Thread: ENUM Function

1. ## ENUM Function

Need a little help to figure out an ENUM problem. This is not the code or the specific problem. I'm trying to create an example that will help me understand ENUM. The tutorials haven't helped.

I have declared:

Enum Directions { North, South, East, West };
Void Cardinal ( Directions);

The program intends to cout the direction when desired by calling a function.

Cardinal [ North ] ; or [South]; or etc.

That called a function:

Void Cardinal ( Directions )

To cout << “The direction is “ <<

Can you help me with the code for the Void Cardinal Function?

2. Enum should be enum.Void should be void.

void Cardinal ( Directions);
enum Directions={NORTH,SOUTH,EAST,WEST};

void Cardinal ( Directions a)
{
if (a==NORTH) cout<<"North";
if (a==SOUTH) cout<<"South";
if (a==EAST) cout<<"East";
if (a==WEST) cout<<"West";
}

3. This is good - Thanks.

How do I call the function.

Something like:

If ( x == 4 )

4. Ignore that reply - Hit wrong key - Sorry.

Back to the problem.

If the program has a set of lines - say:

if ( x == 4 )
cout << cardinal ( )

What goes in the ( ) ? What is the call out using the ENUM? Meaning what is the correct syntax?

5. Cardinal (NORTH)
or
Cardinal (SOUTH)

etc.

Popular pages Recent additions