< previous page page_581 next page >

Page 581
//******************************************************************

void CheckM( /* in */  char    thirdChar,      // 3rd input char
             /* out */ Months&  month,         // Resulting month
             /* out */ Boolean& badData   )    // True if 3rd char
                                               //   bad

// Determines month beginning with M

// Precondition:
//     thirdChar is assigned
// Postcondition:
//     IF thirdChar == 'r' or 'y'
//           badData == FALSE
//        && month == MARCH, if thirdChar == 'r'
//                 == MAY, otherwise
//     ELSE
//           badData == TRUE  && month is undefined

{
    badData = (thirdChar != 'r' && thirdChar !='y');
    if ( !badData )
        if (thirdChar == 'r') 
            month = MARCH;
        else
            month = MAY;
}
Testing and Debugging Hints
1. Avoid using unnecessary side effects in expressions. The test
if ((x = y) < z)
    .
    .
    .
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
is less clear and more prone to error than the equivalent sequence of statements
x = y;
if (y < z)
    .
    .
    .

 
< previous page page_581 next page >