demonstrates enumerations : enum « Data Type « C++






demonstrates enumerations

   
#include <iostream>   
  using namespace std;   
    
  const int jack = 11;
  const int queen = 12;   
  const int king = 13;   
  const int ace = 14;   
    
  enum Suit { clubs, diamonds, hearts, spades };   
  struct card{   
     int number;
     Suit suit; 
    };   
  int main()   
     {   
     card temp, chosen, prize; 
     int position;   
    
     card card1 = { 7, clubs };
     cout << "Card 1 is the seven of clubs\n";   
    
     card card2 = { jack, hearts };
     cout << "Card 2 is the jack of hearts\n";   
    
     card card3 = { ace, spades }; 
     cout << "Card 3 is the ace of spades\n";   
    
     prize = card3;              
    
     if(chosen.number == prize.number &&  chosen.suit == prize.suit)   
        cout << "That's right!  You win!\n";   
     else   
        cout << "Sorry. You lose.\n";   
     return 0;   
  }
  
    
    
  








Related examples in the same category

1.Using consts and enums in Arrays
2.Using bit fields.
3.demonstrates enum types
4.demonstrates enums, counts words in phrase