< previous page page_542 next page >

Page 542
               else
                   inPatient = REPTILE;
               break;
    case C : inPatient = CAT;
               break;
    case D : inPatient = DOG;
               break;
    case B : if (ch2 == i)
                   inPatient = BIRD;
               else
                   inPatient = BOVINE;
               break;
    case H : inPatient = HORSE;
               break;
    default : inPatient = SHEEP;
}
Enumeration type values cannot be printed directly either. Printing is done by using a Switch statement that prints a character string corresponding to the value.
switch (inPatient)
{
    case RODENT  : cout < Rodent;
                   break;
    case CAT     : cout < Cat;
                   break;
    case DOG     : cout < Dog;
                   break;
    case BIRD    : cout < Bird;
                   break;
    case REPTILE : cout < Reptile;
                   break;
    case HORSE   : cout < Horse;
                   break;
    case BOVINE  : cout < Bovine;
                   break;
    case SHEEP   : cout < Sheep;
}
You might ask, Why not use just a pair of letters or an integer number as a code to represent each animal in a program? We use enumeration types to make our programs more readable; they are another way to make code self-documenting.
Returning a Function Value
We have been using value-returning functions to compute and return values of built-in types such as int, float, and char:

 
< previous page page_542 next page >