The following program reads the letter from A to Z and prints it's corresponding telephone digit. This program uses a sentinal controlled while loop . To stop the program user is promoted for the sentinal which is # .
The following program reads the letter from A to Z and prints it's corresponding telephone digit. This program uses a sentinal controlled while loop . To stop the program user is promoted for the sentinal which is # .
SOURCE CODE :-
#include <iostream>
using namespace std;
int main()
{
char letter ;
cout << "This is a program to convert uppercase Letter from A to Z into their corresponding telephone digit " << endl ;
cout << "To stop this program enter # " << endl ;
cout << "Enter an uppercase letter : " << endl ;
cin >> letter ;
while (letter != '#' )
{
cout << "The letter you entered is " << letter << " and the corresponding telephone digit is : " << endl ;
if (letter >= 'A' && letter <= 'Z' )
{
switch (letter)
{
case 'A' :
case 'B' :
case 'C' :
cout << "2" << endl ;
break ;
case 'D' :
case 'E' :
case 'F' :
cout << "3" << endl ;
break ;
case 'G' :
case 'H' :
case 'I' :
cout << "4" << endl ;
break ;
case 'J' :
case 'K' :
case 'L' :
cout << "5" << endl ;
break ;
case 'M' :
case 'N' :
case 'O' :
cout << "6" << endl ;
break ;
case 'P' :
case 'Q' :
case 'R' :
case 'S' :
cout << "7" << endl ;
break ;
case 'T' :
case 'U' :
case 'V' :
cout << "8" << endl ;
break ;
case 'W' :
case 'X' :
case 'Y' :
case 'Z' :
cout << "9" << endl ;
break ;
}
}
else
cout << "Invalid input "<< endl ;
cout << "Enter another uppercase letter to find it's corresponding telephone digit, To stop the program please enter '#' " << endl ;
cin >> letter ;
cout << endl ;
}
return 0 ;
}
Follow us for more posts like this ........
Comments
Post a Comment