ENUM Function

This is a discussion on ENUM Function within the C++ Programming forums, part of the General Programming Boards category; Need a little help to figure out an ENUM problem. This is not the code or the specific problem. I'm ...

  1. #1
    Unregistered
    Guest

    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. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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";
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Unregistered
    Guest
    This is good - Thanks.

    How do I call the function.

    Something like:

    If ( x == 4 )

  4. #4
    Unregistered
    Guest
    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. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Cardinal (NORTH)
    or
    Cardinal (SOUTH)

    etc.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. dynamic function execution
    By Sargnagel in forum C Programming
    Replies: 7
    Last Post: 05-07-2003, 05:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21