View Single Post
  #2 (permalink)  
Old October 31st, 2004, 07:51 PM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you have two ascii characters, say c1 and c2, just convert to an int and do the switch:

Code:
#include <cctype>

int main()
{

char c1, c2;
  int invalue;

  // stuff here to get the chars

  if (!std::isdigit(c1) || !std::isdigit(c2)) {
   // do whatever you must for invalid inputs
  }
  else {
    invalue = (c1 - '0') * 10 + (c2 - '0');

    switch(invalue) {
      case 0: cmd0();
              break;

      case 3: cmd3();
              break;

       // other valid cases here

      default: // error routine here for invalid input numbers

    }
  }
}
Does this do it?

Regards,

Dave
Reply With Quote