#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
int output;
char input;
cout << "Hello, today we will translate a letter from a phone key pad into \n"
"into a corresponding digit " <<endl;
cout << "Please enter a letter you would like translated: ";
cin >> input;
if (input == 'a', 'b', 'c')
{
input=toupper(input);
output = 2;
}
if (input == 'd', 'e', 'f')
{
input=toupper(input);
output = 3;
}
if (input == 'g', 'h', 'i')
{
input=toupper(input);
output = 4;
}
if (input == 'j', 'k', 'l')
{
input=toupper(input);
output = 5;
}
if (input == 'm', 'n', 'o')
{
input=toupper(input);
output = 6;
}
if (input == 'p', 'q', 'r', 's')
{
input=toupper(input);
output = 7;
}
if (input == 't', 'u', 'v')
{
input=toupper(input);
output = 8;
}
if (input == 'w', 'x', 'y', 'z')
{
input=toupper(input);
output = 9;
}
else
{
cout << "Sorry incorrect input \n";
}
cout << "The letter " << input<< " Corresponds to the digit: " <<output <<endl;
return 0;
}
For this assignment my objective was to take in a char data type and display its corresponding telephone key pad digit. When ever compiled my out always shows up as follows :
/*Hello, today we will translate a letter from a phone key pad into into a corresponding digit Please enter a letter you would like translated: a The letter A Corresponds to the digit: 9 Press any key to continue . . . */
I have tried reassigning my conditional statements to have the =, >=, and <= operators but with no luck on getting the proper output to display. Any suggestions as to what I could do to make my output not read as 9 regardless of what I input? Any help would be greatly appreciated!

New Topic/Question
Reply



MultiQuote




|