Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 980055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:19:07+00:00 2026-05-16T04:19:07+00:00

I am writing a program that takes letters and converts them to telephone numbers.

  • 0

I am writing a program that takes letters and converts them to telephone numbers. I am just starting out in c++ and not really familar with classes or members which most of the examples I’ve seen on the web involve these concepts. I have the switch case portion working but cannot get the end of file part right. I have copied my code below:


  //Explanation of Program
  //This program converts inputted characters into numbers based on the telephone digit scheme    
  //**************************************Program begins here******************************************************************
  #include <iostream>         //Includes library file for input / output functionality
  using namespace std;

  int main()
  {
    //Declaration of variables
    char cCharacter = 0;  // User inputed character
    char cNumber = 0;  // Converted numbers from inputed characters

    //Beginning of main program
    cout << "This program converts inputted characters into numbers based on the telephone digit scheme";  //Explanation of program
    while ( cCharacter != EOF)
    {
      cout << endl <<"Please hit '<ctrl> z' to exit, or enter a word on character at a time: ";
      cin >> cCharacter;
      cCharacter = toupper (cCharacter);

      if (cCharacter == EOF)
      {
        break;
      }

      switch (cCharacter)
      {
        case 'A':
        case 'B':
        case 'C':
          cNumber = '2';   
        break;

        case 'D':
        case 'E':
        case 'F':
          cNumber = '3';
        break;

        case 'G':
        case 'H':
        case 'I':
          cNumber = '4';
        break;

        case 'J':
        case 'K':
        case 'L':
          cNumber = '5';
        break;

        case 'M':
        case 'N':
        case 'O':
          cNumber = '6';
        break;

        case 'P':
        case 'Q':
        case 'R':
        case 'S':
          cNumber = '7';
        break;

        case 'T':
        case 'U':
        case 'V':
          cNumber = '8';
        break;

        case 'W':
        case 'X':
        case 'Y':
        case 'Z':
          cNumber = '9';
        break;
      }

      cout << "The number associated with the letter "<< cCharacter <<" is: "<<cNumber <<endl;
    }
    return 0;
  }

Also, I would like to know if there is a way (maybe using arrays) to store each number and then print each in sequence. I don’t think there is beacuse my array would have to be variable length, though.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:19:08+00:00Added an answer on May 16, 2026 at 4:19 am

    I would change a number of things, but as a intro CS program, it’s not too bad. A few things:

    1. Whenever EOF occurs, your cout is going to try to display that EOF and will probably not work correctly. You should at least put an if check on the cout after the while loop checking against cCharacter != EOF to prevent that.

    2. You have no default case. If an input occurs that you don’t expect, you cout will display its intialized 0 or the previous entry for the number.

    3. To store each number and print them in sequnce, the easiest way would be to use a std::vector. These won’t be taught for a while though, so don’t worry about that too much. You could do it unsafely with a large array, but that isn’t a good method as you surmised.

    4. You could also use an array table to replace your switch statement, but again that’s probably a but further along than your class.

    5. I’m sure there’s a getChar method for cin. This would grab each character as it’s typed and would be much cleaner to use than a straight cin.

    I hope this helps you a bit. Without further info from you on how the program is failing, I can only take educated guesses at what is wrong besides the above list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing a program that takes other programs, copies them, and stores
Ok basically I'm writing a program that takes in two directories and processes them
So I am currently writing a part of a program that takes user text
I am writing a program that takes a file and splits it up into
I am writing a program that takes in input various lecture requests that need
I'm writing a program that takes some input of names and looks at a
I have a rookie question. I'm currently writing a program that takes in alot
I'm writing a program that sends an email out at a client's specific local
I am writing a C# program that takes in a bunch of parameters and
Please help me in writing a Program that takes a single digit or value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.