Hi Guys!
Was wondering what I was doing wrong with this program. This a program that when a person enters a number, 2-9, it gives them the letters that correspond just like on your phone, e.g., 2 is a,b,c. They also have to chose if they want a switch statement or a nested by selecting 1 or 2 to give them their answer. I am getting some errors with the else statement that connects the switch and the nested. Can anybody show me what I am doing wrong. It must be able to run on either the switch or nested depending on user selection. Thanks again from a new programmer! :)
int main()
{
int digit;
int character;
int select = -1;
{
cout << "What function do you want to use : " << endl;
cout << "1) Switch Statement " << endl;
cout << "2) Nested Statement" << endl << endl;
cout << "Enter: ";
cin >> select;
if (select == 1)
{
cout << " Enter the letter you want to see as a number: ";
cin >> character;
switch (digit)
{
case '2':
cout << " A, B, C";
case '3':
cout << " C, D, E";
case '4':
cout << " G, H, I";
case '5':
cout << " J, K ,L";
case '6':
cout << " M, N, O";
case '7':
cout << " P, Q, R, S";
case '8':
cout << " T, U, V";
case '9':
cout << " W, X, Y, Z";
default:
cout << digit<< "Error! Is not a number between 2-9 ."
<< endl;
return 0;
}
else
if (select == 2)
{
cout <<" Enter the number you want see its corresponding letters: ";
cin >> digit;
if ( digit == 2)
cout << digit << " A, B, C" << endl;
else
if ( digit == 3)
cout << digit << " D, E, F" << endl;
else
if ( digit == 4)
cout << digit << " G, H, I" << endl;
else
if ( digit == 5)
cout << digit << " J, K, L" << endl;
else
if ( digit == 6)
cout << digit << " M, N, 0" << endl;
else
if ( digit == 7)
cout << digit << " P, Q, R, S" << endl;
else
if ( digit == 8)
cout << digit << " T, U, V" << endl;
else
if ( digit == 9)
cout << digit << " P, Q, R, S" << endl;
else
cout << digit << "Error! Is not a number between 2-9 ." << endl;
system ("pause");
return 0;
}
else
cout << "Valid options are only 1 or 2." << endl;
system ("pause");
}
return 0;
}