Enum Program 3

Description:

In this C++ example, we demonstrate how to use an enum to define a type that could be used to represent prime number values.

Example

#include <iostream>

// We can define an enum to represent some prime numbers.
// Unspecified values are one more than the previous value.
// In this case, keTwo = 2, keThree = 3, keFive = 5, keSeven = 7.
enum EPrimeNum {keTwo = 2, keThree, keFive = 5, keSeven = 7};

int main() {
    using namespace std;

    // Create an instance of the type and assign it the value keThree.
    EPrimeNum eMyPrime = keThree;

    cout << "Prime enum value = " << eMyPrime << endl;
    // Output the constant enum values.
    cout << "keTwo = " << keTwo << endl;
    cout << "keThree = " << keThree << endl;
    cout << "keFive = " << keFive << endl;
    cout << "keSeven = " << keSeven << endl;

    // Keep the console window open.
    cin.get();
    return 0;
}

Output:

Enum Program 3 Output