#include<iostream>
using namespace std;
void convertLetter(char);
void convertWord(char);
int main()
{
	char input;
	do
	{
		cout << "Please make a selection\nS:\tConvert a single letter to its corresponding telephone digit\nW:\tConvert a word to its corresponding telephone number\nQ:\tExit" << endl;
		cin >> input;
		if (input == 's' || input == 'S')
			convertLetter(input);
		else if (input == 'w' || input == 'W')
			convertWord(input);
	}
	while (input != 'q' && input != 'Q');
	return 0;
}
void convertLetter(char s)
{
	cout << "Program to convert letters to their corresponding digit." << endl;
	do
	{
		cout << "To stop the program enter #:\nEnter a letter: ";
		cin >> s;
		switch (s)
		{
		case 'a' : case 'b' : case 'c' : case 'A' : case 'B' : case 'C' : cout << "\nThe corresponding telephone digit is 2\n" << endl; break;
		case 'd' : case 'e' : case 'f' : case 'D' : case 'E' : case 'F' : cout << "\nThe corresponding telephone digit is 3\n" << endl; break;
		case 'g' : case 'h' : case 'i' : case 'G' : case 'H' : case 'I' : cout << "\nThe corresponding telephone digit is 4\n" << endl; break;
		case 'j' : case 'k' : case 'l' : case 'J' : case 'K' : case 'L' : cout << "\nThe corresponding telephone digit is 5\n" << endl; break;
		case 'm' : case 'n' : case 'o' : case 'M' : case 'N' : case 'O' : cout << "\nThe corresponding telephone digit is 6\n" << endl; break;
		case 'p' : case 'q' : case 'r' : case 's' : case 'P' : case 'Q' : case 'R' : case 'S' : cout << "\nThe corresponding telephone digit is 7\n" << endl; break;
		case 't' : case 'u' : case 'v' : case 'T' : case 'U' : case 'V' : cout << "\nThe corresponding telephone digit is 8\n" << endl; break;
		case 'w' : case 'x' : case 'y' : case 'z' : case 'W' : case 'X' : case 'Y' : case 'Z' : cout << "\nThe corresponding telephone digit is 9\n" << endl; break;
		case '#' : cout << "\nBye.\n" << endl; break;
		default : cout << "\nInvalid input.\n" << endl;
		}
	}
	while (s != '#');
}
void convertWord(char)
{
	int digit[8];
	char letter, yesno;
	cout << "Program to convert words to their corresponding telephone digits.";
	do
	{
		cout << "\nPlease enter an 8 character word: ";
		for (int w = 0; w < 8; w++)
		{
			cin >> letter;
			switch (letter)
			{
				case 'a' : case 'b' : case 'c' : case 'A' : case 'B' : case 'C' : digit[w] = 2; break;
				case 'd' : case 'e' : case 'f' : case 'D' : case 'E' : case 'F' : digit[w] = 3; break;
				case 'g' : case 'h' : case 'i' : case 'G' : case 'H' : case 'I' : digit[w] = 4; break;
				case 'j' : case 'k' : case 'l' : case 'J' : case 'K' : case 'L' : digit[w] = 5; break;
				case 'm' : case 'n' : case 'o' : case 'M' : case 'N' : case 'O' : digit[w] = 6; break;
				case 'p' : case 'q' : case 'r' : case 's' : case 'P' : case 'Q' : case 'R' : case 'S' : digit[w] = 7; break;
				case 't' : case 'u' : case 'v' : case 'T' : case 'U' : case 'V' : digit[w] = 8; break;
				case 'w' : case 'x' : case 'y' : case 'z' : case 'W' : case 'X' : case 'Y' : case 'Z' : digit[w] = 9; break;
			}
		}
		if (letter != '#')
		{
			for (int w = 0; w < 8; w++)
			{
				
				cout << digit[w];
				if (w == 3)
					cout << "-";
			}
		    cout << "\nDo you wish to enter another number? ";
			cin >> yesno;
		}
	}
	while (yesno == 'y');
}

I'm doing a work,this my question..
Please make a selection
S: Convert a single letter to its corresponding telephone digit
W: Convert a word to its corresponding telephone number
Q: Exit

Program to convert words to their corresponding telephone digits
To stop the program enter #:
Please enter an 8 character word: CALLHOME
Word Number
---------------------
CALLHOME 2255-4667
---------------------
Do you wish to display another number? Y
Please enter an 8 character word: MoneyHelp
Word Number
---------------------
MoneyHelp 6663-9435
---------------------
Do you wish to display another number? N
BYE!
----------------------------------------------------------------
My problem is how I make this :
Word Number
---------------------
CALLHOME 2255-4667
---------------------

can any help???

Edited 4 Years Ago by vincent5487: n/a

declare

char chars[8];

then in each case

...digit[w] = X;chars[w]=letter; break;

finally

for (int w = 0; w < 8; w++)
{
	cout << chars[w];
}

for (int w = 0; w < 8; w++)
{			
	cout << digit[w];
	if (w == 3)
		cout << "-";
}

You should capitalize the input, and make the code easier to read.
A simple example:
if (myChar >= 'a' && myChar <= 'd') myInt = 1;

declare

char chars[8];

then in each case

...digit[w] = X;chars[w]=letter; break;

finally

for (int w = 0; w < 8; w++)
{
	cout << chars[w];
}

for (int w = 0; w < 8; w++)
{			
	cout << digit[w];
	if (w == 3)
		cout << "-";
}

Thx dude :D i solve the problem rdy~thx for giving me the way~

can i ask after my thing done,i request to go back at
Please enter an 8 character word: MoneyHelp
Word Number
---------------------
MoneyHelp 6663-9435
---------------------
Do you wish to display another number? N
BYE!

but my code back to the selection there...how should i change my code by not going back to the selection there??

This article has been dead for over six months. Start a new discussion instead.