Use enumerated constants for the eight compass directions, - C++ Data Type

C++ examples for Data Type:enum

Description

Use enumerated constants for the eight compass directions,

Demo Code

#include <iostream> 

int main() /*from w w  w . j av a2 s. c o  m*/
{ 
    enum Direction { North, Northeast, East, Southeast, South, Southwest, West, Northwest }; 
 
    // create a variable to hold it 
    Direction heading; 
    // initialize that variable 
    heading = Southeast; 
 
    std::cout << "Moving " << heading << std::endl; 
    return 0; 
}

Result


Related Tutorials