< previous page page_565 next page >

Page 565
//          Player A's play has been read from fileA and Player B's
//          play has been read from fileB
//       && IF both plays are legal
//            legal == TRUE
//          && playForA == PlayType equivalent of Player A's play
//                         char
//          && playForB == PlayType equivalent of Player B's play
//                         char
//        ELSE
//            legal == FALSE
//          && playForA and playForB are undefined

{
  char charForA;      // Player A's input
  char charForB;      // Player B's input
  fileA >> charForA;         // Skip whitespace, including newline
  fileB >> charForB;
  if ( !fileA || !fileB)
      return;
  legal = (charForA==R || CharForA==P || charForA==S) &&
          (charForB==R || charForB==P || charForB==S);
  if (legal)
  {
      playForA = ConversionVal(charForA);
      playForB = ConversionVal(charForB);
  }
}
//*****************************************************************

PlayType ConversionVal( /* in */ char someChar )   // Play character

// Converts a character into an associated value of PlayType

// Precondition:
//     someChar == R or P or S
// Postcondition:
//     Function value == ROCK, if someChar == R
//                    == PAPER, if someChar == P
//                    == SCISSORS, if someChar == S

{
    switch (someChar)
    {

 
< previous page page_565 next page >