< previous page page_681 next page >

Page 681
Get Month (Out: month) Level 1
DO
  Read strMonth
  Search(strMonthAry, strMonth, 12, index, found)
  IF found
      Set month = monthAry[index]
  ELSE
    Print error message
WHILE NOT found

Now we can code the new function GetMonth. We must remember to initialize the arrays strMonthAry and monthAry. We also need to modify the Search function to make it work on string data.
#include <string.h>        // For strcmp()
  .
  .
  .
typedef char String9[10];   // Room for 9 characters plus '\0'
  .
  .
  .

//******************************************************************

void GetMonth( /* out */ Months& month )    // User's desired month

// Inputs a month after prompting the user

// Postcondition:
//     User has been prompted to enter a month
//  && On invalid input, the user has been repeatedly prompted to
//     type a correct month
//  && month == value of type Months corresponding to user's input

{
    String9 strMonth;               // Input month in string form
    Months  monthAry[12] =          // Table of months in enum form
    {
        JANUARY, FEBRUARY, MARCH, APRIL,
        MAY, JUNE, JULY, AUGUST,
        SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER
    };

 
< previous page page_681 next page >