c++ - How to take input in integers and print message (numeric keypad) -


i have searched on internet specific method there not looking for. wrote program takes input in integers , prints message( in numeric keypad of cellphones). want program take input in 1 line

enter code crack : 454545479833165445 

and corresponding message gets printed. rather than

enter code crack :55 enter code crack : 666 

and prints message when press specific key -1 in case.

  #include <iostream>   using namespace std;  int main() { int a; string n; do{     cout << "enter code crack";     cin >>a;      switch (a){      case 0:     {       n=n+" ";}     break;      case 1:         {       n=n+".";}     break;      case 11:         {       n=n+",";}      break;      case 2:{      n=n+"a";}     break;      case 22:     n=n+"b";     break;      case 222:     n=n+"c";     break;      case 3:     n=n+"d";     break;      case 33:     n=n+"e";     break;      case 333:     n=n+"f";     break;        case 4:     n=n+"g";     break;      case 44:     n=n+"h";     break;      case 444:     n=n+"i";     break;       case 5:     n=n+"j";     break;      case 55:     n=n+"k";     break;      case 555:     n=n+"l";     break;        case 6:     n=n+"m";     break;      case 66:     n=n+"n";     break;      case 666:     n=n+"o";     break;       case 7:     n=n+"p";     break;      case 77:     n=n+"q";     break;      case 777:     n=n+"r";     break;        case 7777:     n=n+"s";     break;      case 8:     n=n+"t";     break;      case 88:     n=n+"u";     break;       case 888:     n=n+"v";     break;      case 9:     n=n+"w";     break;      case 99:     n=n+"x";     break;       case 999:     n=n+"y";     break;      case 9999:     n=n+"z";     break;} } while(a!=-1); cout <<"the decoded message :" << n;  return 0; } 

if want process 1 signle input, assuming many digits message contain overflow lognest integer type, have use string input, , iterate through chars:

string a; string n;  cout << "enter code crack"; cin >>a;   // you'll everything, each digit char   (int i=0; i<a.size(); i++) {     //... process each separate digit a[i] here  } cout <<"the decoded message :" << n; 

each digit a[i] between '0' , '9'. you'll have take care of 2 difficulties:

  • the string might contain illegal caracters (for example alphanumeric), have handle these cases, issuing error message
  • each string arives separately. no 44 anymore, '4' , '4'. have take account in ralgorithm previous digit, see if have fo shift last output letter one, or if have new output letter.

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -