1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#include <iostream>
#include <cctype>//using this library for toupper conversion
using namespace std;
int main()
{
char choice;
char VIEW = '$';//declare $
do//begin do-while that will run the program for any choice input except $ which should terminate the program
{
cout << endl
<< "Enter A, B, or C for digit 2\n"
<< "Enter D, E, or F for digit 3\n"
<< "Enter G, H, or I for digit 4\n"
<< "Enter J, K, or L for digit 5\n"
<< "Enter M, N, or O for digit 6\n"
<< "Enter P, R, or S for digit 7\n"
<< "Enter T, U, or V for digit 8\n"
<< "Enter W, X, or Y for digit 9\n";
cin >> choice;//user inputs a character
//command to convert any upper case letters to lowercase
{
cout << "You entered a lowercase letter and now I will convert it to uppercase for you.\n";
cout << (char)toupper(choice);//if the choice is a lowercase letter, convert to uppercase
}
//command to prompt user to enter a new choice if they enter these characters until they enter something valid
while (choice == 'q' || choice == 'Q' || choice == 'z' || choice == 'Z')//while the user enters any of these chars, they will be prompted to re-enter a new choice until they enter something valid
{
!((char)toupper(choice));//negate output that letter will be made uppercase
cout << "No digit corresponds to" << choice << endl;
cout << "Enter a new letter";
cin >> choice;
}
//begin switch statement for valid choice entries
switch (choice)
{
case 'A':
cout << "2" << endl;
break;
case 'B':
cout << "2" << endl;
break;
case 'C':
cout << "2" << endl;
break;
case 'D':
cout << "3" << endl;
break;
case 'E':
cout << "3" << endl;
break;
case 'F':
cout << "3" << endl;
break;
case 'G':
cout << "4" << endl;
break;
case 'H':
cout << "4" << endl;
break;
case 'I':
cout << "4" << endl;
break;
case 'J':
cout << "5" << endl;
break;
case 'K':
cout << "5" << endl;
break;
case 'L':
cout << "5" << endl;
break;
case 'M':
cout << "6" << endl;
break;
case 'N':
cout << "6" << endl;
break;
case '0':
cout << "6" << endl;
break;
case 'P':
cout << "7" << endl;
break;
case 'R':
cout << "7" << endl;
break;
case 'S':
cout << "7" << endl;
break;
case 'T':
cout << "8" << endl;
break;
case 'U':
cout << "8" << endl;
break;
case 'V':
cout << "8" << endl;
break;
case 'W':
cout << "9" << endl;
break;
case 'X':
cout << "9" << endl;
break;
case 'Y':
cout << "9" << endl;
break;
case '$':
cout << "The $ terminates this program" << endl;//tells user the program will terminate
break;
//default for special characters
default:
cout << "Not a valid choice, which means you entered a special character or number. Re-enter a choice.\n";
}
} while (choice != '$');//close do-while that will run the program for any choice input except $ which should terminate the program
return 0;
}
|