// FILE: ToDigit.cpp #include // for isdigit () // DETERMINES THE EQUIVALENT INTEGER FORM OF ITS CHARACTER INPUT bool to_digit (char ch, // IN: the character to be converted int& i) // OUT: the integer form of ch (or -1) // Pre : ch must be a digit character. // Post: converts ch to a decimal digit // Returns: true if ch is a digit character and false otherwise. // Also returns through the output argument i the // integer form of the character input argument // (or -1 if this character is not a digit). { // Determine if ch is a digit character. if (isdigit (ch)) { i = int (ch) - int ('0'); return true; } else { i = -1; return false; } } // end to_digit