Find Telephone Digit of Alphabet
Find Telephone Digit of Alphabet:
The following program reads the letter codes A to Z and prints the corresponding telephone digit. This program uses a sentinel-controlled while loop. To stop the program, the user is prompted for the sentinel, which is #. This is also an example of a nested control structure, where if...else and the while loop are nested.
--> Sample Run: In this sample run, the user input is shaded.
Program to convert uppercase letters to their corresponding telephone
digits.
To stop the program enter #.
Enter a letter: A
Letter: A, Corresponding telephone digit: 2
Enter another uppercase letter to find its corresponding telephone digit.
To stop the program enter #.
Enter a letter: M
Letter: M, Corresponding telephone digit: 6
282 | Chapter 5: Control Structures II (Repetition)
Enter another uppercase letter to find its corresponding telephone digit.
To stop the program enter #.
Enter a letter: Q
Letter: Q, Corresponding telephone digit: 7
Enter another uppercase letter to find its corresponding telephone digit.
To stop the program enter #.
Enter a letter: V
Letter: V, Corresponding telephone digit: 8
Enter another uppercase letter to find its corresponding telephone
digit.
To stop the program enter #.
Enter a letter: Y
Letter: Y, Corresponding telephone digit: 9
Enter another uppercase letter to find its corresponding telephone digit.
To stop the program enter #.
Enter a letter: #
Comments
Post a Comment