c++ LOOP, HELP!

This is a discussion on c++ LOOP, HELP! within the C++ Programming forums, part of the General Programming Boards category; 1.Write a program that will ask the user to input a hexadecimal number then convert and display the decimal equivalent ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    3

    c++ LOOP, HELP!

    1.Write a program that will ask the user to input a hexadecimal number then convert and display the decimal equivalent of the hexadecimal number.

    The program should process the program as many times as the user wants.





    2. To make a telephone numbers 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. Write a program that prompts the user to enter a telephone number in digits. Allow the user to use both uppercase and lowercase letters as well as space between words.

    The program should process the program as many times as the user wants.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,275
    What have you done so far?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    3
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    main:
        char ch1;
        int num1;
        bool repeat;
        char yes;
    
        cout << "Enter your telephone number in letters." << endl;
        cin >> ch1;
        cout << "\n";
    
            for (int i=0; i < 7; i++)
            {
                    switch (ch1)
                    {
                        case 'A':
                        case 'B':
                        case 'C':
                        case 'a':
                        case 'b':
                        case 'c':
                                cout << "2";
                                cin >> ch1;
                                break;
                        case 'D':
                        case 'E':
                        case 'F':
                        case 'd':
                        case 'e':
                        case 'f':
                                cout << "3";
                                cin >> ch1;
                                break;
                        case 'G':
                        case 'H':
                        case 'I':
                        case 'g':
                        case 'h':
                        case 'i':
                                cout << "4";
                                cin >> ch1;
                                break;
                        case 'J':
                        case 'K':
                        case 'L':
                        case 'j':
                        case 'k':
                        case 'l':
                                cout << "5";
                                cin >> ch1;
                                break;
                        case 'M':
                        case 'N':
                        case 'O':
                        case 'm':
                        case 'n':
                        case 'o':
                                cout << "6";
                                cin >> ch1;
                                break;
                        case 'P':
                        case 'Q':
                        case 'R':
                        case 'S':
                        case 'p':
                        case 'q':
                        case 'r':
                        case 's':
                                cout << "7";
                                cin >> ch1;
                                break;
                        case 'T':
                        case 'U':
                        case 'V':
                        case 't':
                        case 'u':
                        case 'v':
                                cout << "8";
                                cin >> ch1;
                                break;
                        case 'W':
                        case 'X':
                        case 'Y':
                        case 'Z':
                        case 'w':
                        case 'x':
                        case 'y':
                        case 'z':
                                cout << "9";
                                cin >> ch1;
                                break;
                    }
            }
    
                cout << "\n\nwould you like to repeat the operation? Y/N" << endl;
                cin >> yes;
                cout << "\n" << endl;
            if (yes == 'Y')
            {
               goto main;
            }
            else
            {
                goto end;
            }
    end:
        return 0;
    }
    I don't know how to convert from numbers to letters T_T

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,275
    Instead of two goto statements and two labels, make use of a loop, e.g., a while loop or a do while loop.

    Quote Originally Posted by Ejing2
    I don't know how to convert from numbers to letters
    First, you need to be clear on what your program is supposed to do. You are supposed to "write a program that prompts the user to enter a telephone number in digits". Then, what output is your program supposed to have? After all, a digit corresponds to multiple possible letters.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-26-2011, 07:36 PM
  2. Nested while loop inside for loop
    By Sonny in forum C Programming
    Replies: 71
    Last Post: 07-31-2011, 09:38 PM
  3. Replies: 23
    Last Post: 04-05-2011, 04:40 PM
  4. for loop ignoring scanf inside loop
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-17-2007, 02:46 AM
  5. stays in loop, but it's not an infinite loop (C++)
    By Berticus in forum C++ Programming
    Replies: 8
    Last Post: 07-19-2005, 12:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21