C++ Program to Convert English Words into Phone Numbers
#include<iostream.h>
#include<conio.h>
void main()
{
char letter;
int sum = 0;
cout<<"enter digit :"<<endl;
while ( cin>>(letter) && sum < 7 )
{
if (letter != ' ' && letter >= 'a' && letter <= 'z' && letter >= 'A' && letter <= 'z') sum++;
if (letter > 'Z' && letter > 'z')
{
letter = (int)letter-32;
}
if(sum == 4)
{
cout << "-";
}
switch (letter)
{
case 'a':
case 'b':
case 'c':
cout << "2";
break;
case 'd':
case 'e':
case 'f':
cout << "3";
break;
case 'g':
case 'h':
case 'i':
cout << "4";
break;
case 'j':
case 'k':
case 'l':
cout << "5";
break;
case 'm':
case 'n':
case 'o':
cout << "6";
break;
case 'p':
case 'q':
case 'r':
case 's':
cout << "7";
break;
case 't':
case 'u':
case 'v':
cout << "8";
break;
case 'w':
case 'x':
case 'y':
case 'z':
cout << "9";
cout<<"\n";
break;
case 'A':
case 'B':
case 'C':
cout << "2";
break;
case 'D':
case 'E':
case 'F':
cout << "3";
break;
case 'G':
case 'H':
case 'I':
cout << "4";
break;
case 'J':
case 'K':
case 'L':
cout << "5";
break;
case 'M':
case 'N':
case 'O':
cout << "6";
break;
case 'P':
case 'Q':
case 'R':
case 'S':
cout << "7";
break;
case 'T':
case 'U':
case 'V':
cout << "8";
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
cout << "9";
cout<<"\n";
break;
default:
cout << "Invalid input" << endl;
getch();
}
}
}