Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,261 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,245 people online right now. Registration is fast and FREE... Join Now!




Converting letters to numbers

 
Reply to this topicStart new topic

Converting letters to numbers, HELP!!

kimchizzz
19 Apr, 2008 - 08:59 PM
Post #1

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 5

To make telephone easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone number in digits. If the user enters more than 7 letters, then process only the first seven letters. Also output the - (hyphen) after the third digit. Allow the user to use both uppercase and lowercase letters as well as spaces between words. Moreover, your program should process as many telephone numbers as the user wants.

Sample Run

Please enter the text:
Big Deal
The phone number is 244-3325.

The problem is that I can't figure it out why my output is look like

B
2
I
4
G
4

D
3
E
3
A
2
L
5

what should i do?

CODE


#include <iostream>

using namespace std;

int main()
{
    char letter;                                  //Line 1

    cout << "Program to convert uppercase "
         << "letters to their corresponding "  
         << "telephone digits." << endl;          //Line 2

    cout << "To stop the program enter #."
         << endl;                                 //Line 3

    cout << "Enter a letter: ";                   //Line 4
    cin >> letter;                                //Line 5
    cout << endl;                                 //Line 6

    while (letter != '#')                         //Line 7
    {
        cout << "The letter you entered is: "
             << letter << endl;                   //Line 8
        cout << "The corresponding telephone "
             << "digit is: ";                     //Line 9

               //Line 10
            switch (letter)                       //Line 11
            {
            case 'A':
            case 'B':
            case 'C':
                cout << "2" <<endl;               //Line 12
                break;                            //Line 13
            case 'D':
            case 'E':
            case 'F':
                cout << "3" << endl;              //Line 14
                break;                            //Line 15
            case 'G':
            case 'H':
            case 'I':
                cout << "4" << endl;              //Line 16
                break;                            //Line 17
            case 'J':
            case 'K':
            case 'L':
                cout << "5" << endl;              //Line 18
                break;                            //Line 19
            case 'M':
            case 'N':
            case 'O':
                cout << "6" << endl;              //Line 20
                break;                            //Line 21
            case 'P':
            case 'Q':
            case 'R':
            case 'S':
                cout << "7" << endl;              //Line 22
                break;                            //Line 23
            case 'T':
            case 'U':
            case 'V':
                cout << "8" << endl;              //Line 24
                break;                            //Line 25
            case 'W':
            case 'X':
            case 'Y':
            case 'Z':
                cout << "9" << endl;              //Line 26
            default:
                    cout << "Invalid input." << endl;
            }
            
                                            //Line 27
                 //Line 28

        cout << "\nEnter another uppercase "
             << "letter to find its "
             << "corresponding telephone digit."
             << endl;                             //Line 29
        cout << "To stop the program enter #."
             << endl;                             //Line 30

        cout << "Enter a letter: ";               //Line 31
        cin >> letter;                            //Line 32
        cout << endl;                             //Line 33
    }//end while

    return 0;
}


User is offlineProfile CardPM
+Quote Post


no2pencil
RE: Converting Letters To Numbers
19 Apr, 2008 - 09:07 PM
Post #2

Unix Ronin
Group Icon

Joined: 10 May, 2007
Posts: 10,438



Thanked: 198 times
Dream Kudos: 2725
Expert In: Goofing Off

My Contributions
QUOTE(kimchizzz @ 20 Apr, 2008 - 12:59 AM) *

what should i do?

Well, you'll get a better response if you post the question into the correct topic (C/C++), & not in Introduce yourself.

Welcome to Dream In Code!
User is offlineProfile CardPM
+Quote Post

kimchizzz
RE: Converting Letters To Numbers
19 Apr, 2008 - 09:15 PM
Post #3

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 5

To make telephone easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone number in digits. If the user enters more than 7 letters, then process only the first seven letters. Also output the - (hyphen) after the third digit. Allow the user to use both uppercase and lowercase letters as well as spaces between words. Moreover, your program should process as many telephone numbers as the user wants.



Sample Run

Please enter the text for a phone number:
Big Deal
The phone number is 244-3325.
The problem is my output doesn't look like the one from above.

Everytime I input BIG DEAL

The letter you entered is : B
The corresponding telephone digit is : 2

The letter you entered is : I
The corresponding telephone digit is : 4

The letter you entered is : G
The corresponding telephone digit is : 4

and so on.











what should i do to make my output looks like the sample output?


CODE




#include <iostream>

using namespace std;

int main()
{
    char letter;                                  //Line 1

    cout << "Program to convert uppercase "
         << "letters to their corresponding "  
         << "telephone digits." << endl;          //Line 2

    cout << "To stop the program enter #."
         << endl;                                 //Line 3

    cout << "Enter a letter: ";                   //Line 4
    cin >> letter;                                //Line 5
    cout << endl;                                 //Line 6

    while (letter != '#')                         //Line 7
    {
        cout << "The letter you entered is: "
             << letter << endl;                   //Line 8
        cout << "The corresponding telephone "
             << "digit is: ";                     //Line 9

               //Line 10
            switch (letter)                       //Line 11
            {
            case 'A':
            case 'B':
            case 'C':
                cout << "2" <<endl;               //Line 12
                break;                            //Line 13
            case 'D':
            case 'E':
            case 'F':
                cout << "3" << endl;              //Line 14
                break;                            //Line 15
            case 'G':
            case 'H':
            case 'I':
                cout << "4" << endl;              //Line 16
                break;                            //Line 17
            case 'J':
            case 'K':
            case 'L':
                cout << "5" << endl;              //Line 18
                break;                            //Line 19
            case 'M':
            case 'N':
            case 'O':
                cout << "6" << endl;              //Line 20
                break;                            //Line 21
            case 'P':
            case 'Q':
            case 'R':
            case 'S':
                cout << "7" << endl;              //Line 22
                break;                            //Line 23
            case 'T':
            case 'U':
            case 'V':
                cout << "8" << endl;              //Line 24
                break;                            //Line 25
            case 'W':
            case 'X':
            case 'Y':
            case 'Z':
                cout << "9" << endl;              //Line 26
            default:
                    cout << "Invalid input." << endl;
            }
            
                                            //Line 27
                 //Line 28

        cout << "\nEnter another uppercase "
             << "letter to find its "
             << "corresponding telephone digit."
             << endl;                             //Line 29
        cout << "To stop the program enter #."
             << endl;                             //Line 30

        cout << "Enter a letter: ";               //Line 31
        cin >> letter;                            //Line 32
        cout << endl;                             //Line 33
    }//end while

    return 0;
}



This post has been edited by kimchizzz: 19 Apr, 2008 - 09:37 PM
User is offlineProfile CardPM
+Quote Post

mikeblas
RE: Converting Letters To Numbers
19 Apr, 2008 - 09:19 PM
Post #4

D.I.C Regular
Group Icon

Joined: 8 Feb, 2008
Posts: 390



Thanked: 25 times
My Contributions
"endl" writes a new line to cout. Since you're writing endl, you're getting a newline.
User is offlineProfile CardPM
+Quote Post

mikeblas
RE: Converting Letters To Numbers
19 Apr, 2008 - 09:20 PM
Post #5

D.I.C Regular
Group Icon

Joined: 8 Feb, 2008
Posts: 390



Thanked: 25 times
My Contributions
I answered at your other post.

User is offlineProfile CardPM
+Quote Post

kimchizzz
RE: Converting Letters To Numbers
19 Apr, 2008 - 09:21 PM
Post #6

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 5

QUOTE(mikeblas @ 19 Apr, 2008 - 10:20 PM) *

I answered at your other post.


Im sorry im new to this website.

wheres my other post?
User is offlineProfile CardPM
+Quote Post

Mila
RE: Converting Letters To Numbers
19 Apr, 2008 - 09:29 PM
Post #7

D.I.C Head
Group Icon

Joined: 28 Oct, 2006
Posts: 95


Dream Kudos: 25
My Contributions
Here: http://www.dreamincode.net/forums/index.ph...c=49545&hl=
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Converting Letters To Numbers
19 Apr, 2008 - 09:33 PM
Post #8

Unix Ronin
Group Icon

Joined: 10 May, 2007
Posts: 10,438



Thanked: 198 times
Dream Kudos: 2725
Expert In: Goofing Off

My Contributions
QUOTE(mikeblas @ 20 Apr, 2008 - 01:20 AM) *

I answered at your other post.

I asked him to start a thread under the correct topic.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Converting Letters To Numbers
19 Apr, 2008 - 11:32 PM
Post #9

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,353



Thanked: 81 times
Dream Kudos: 2800
Expert In: J2ME, 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Topics Merged.
User is offlineProfile CardPM
+Quote Post

mikeblas
RE: Converting Letters To Numbers
20 Apr, 2008 - 04:52 AM
Post #10

D.I.C Regular
Group Icon

Joined: 8 Feb, 2008
Posts: 390



Thanked: 25 times
My Contributions
QUOTE(kimchizzz @ 19 Apr, 2008 - 10:21 PM) *

QUOTE(mikeblas @ 19 Apr, 2008 - 10:20 PM) *

I answered at your other post.


Im sorry im new to this website.

wheres my other post?

Me, too. I think your other post was removed after being merged with this one--but I don't see a redirect left where the old post was. Now, my original response and my response to this thread are here, out of context.

But -- at least you have your answer!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 11:47AM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month