Is anybody capable of providing me with guidance, not opinions?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Is anybody capable of providing me with guidance, not opinions?

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    1

    Is anybody capable of providing me with guidance, not opinions?

    So the question is:

    People sometimes give their telephone number using one or more alphabetic characters. Write a program that accepts a 10-digit telephone number that may contain one or more alphabetic characters. Display the corresponding number using numerals. The numbers and letters are associated as follows on your telephone:

    ABC:2
    DEF:3
    GHI:4
    JKL:5
    MNO:6
    PQRS:7
    TUV:8
    WXYZ:9

    If the user enters a character that is not on the telephone as part of the number, display a message indicating that the value does not match a number. Allow both upper- and lowercase characters to be entered.

    This must also be created for use in a Windows Form Application, by the way..


    Now, I've been attempting to complete this assignment for the past week. I have tried if statements, for/foreach loops, etc. and I still am unable to finish it properly.

    Here is what I currently have:

    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void bConvert_Click(object sender, EventArgs e)
    {
    ConsoleKeyInfo keyInfo = Console.ReadKey();
    char selectedChar = keyInfo.KeyChar;
    switch (selectedChar)
    {

    case '2':
    case 'A':
    case 'a':
    case 'B':
    case 'b':
    case 'C':
    case 'c':
    break;
    }

    }
    }
    }

    Any tips/examples to show how to complete code? Easier ways to go about completing the task appropriately?
    Thanks people.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    Re: Is anybody capable of providing me with guidance, not opinions?

    that has no IF/THEN or LOOP. What do you think that will do? Have you tried to run it? Does it do anything?

    Please provide a few more samples of *YOUR* code that you have tried?

    Luckily you don't want my OPINION of the above...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: Is anybody capable of providing me with guidance, not opinions?

    First, an opinion is also guidance

    Second, have a look at this article :

    Working with Hashtables in .NET
    http://www.codeguru.com/columns/vb/w...es-in-.net.htm

    It explains how to use Hashtables

    Then, have a look at this code :

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    
    using System.Collections; //The System.Collections namespace contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hashtables and dictionaries.
    
    
    namespace CellNumber_Converter
    {
        public partial class Form1 : Form
        {
            private Hashtable htPhoneNumbers = new Hashtable(); //hashtable to store keys + numbers
            private string strNumber;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                strNumber = textBox1.Text.ToUpper(); //convert entered text to uppercase
    
                foreach (char c in strNumber) //Loop through entered text
                {
                    string digit = c.ToString(); //Convert to string
    
                    if (htPhoneNumbers.ContainsKey(digit)) //if Entered text is any of the keys
                    {
                        label1.Text += htPhoneNumbers[digit]; //add to label
                       
    
                    }
                }
            }
    
            private void Form1_Load(object sender, System.EventArgs e)
            {
                htPhoneNumbers["A"] = "2"; //Store the word "2" inside the hashtable at location "A"  etc.
                htPhoneNumbers["B"] = "2";
                htPhoneNumbers["C"] = "2";
    
                htPhoneNumbers["D"] = "3";
                htPhoneNumbers["E"] = "3";
                htPhoneNumbers["F"] = "3";
    
                htPhoneNumbers["G"] = "4";
                htPhoneNumbers["H"] = "4";
                htPhoneNumbers["I"] = "4";
    
                htPhoneNumbers["J"] = "5";
                htPhoneNumbers["K"] = "5";
                htPhoneNumbers["L"] = "5";
    
                htPhoneNumbers["M"] = "6";
                htPhoneNumbers["N"] = "6";
                htPhoneNumbers["O"] = "6";
    
                htPhoneNumbers["P"] = "7";
                htPhoneNumbers["Q"] = "7";
                htPhoneNumbers["R"] = "7";
                htPhoneNumbers["S"] = "7";
    
                htPhoneNumbers["T"] = "8";
                htPhoneNumbers["U"] = "8";
                htPhoneNumbers["V"] = "8";
    
                htPhoneNumbers["W"] = "9";
                htPhoneNumbers["X"] = "9";
                htPhoneNumbers["Y"] = "9";
                htPhoneNumbers["Z"] = "9";
            }
        }
    }
    Fourth, have a lookm at the attachment.

    Fifth, Read the abovementioned article properly, else, this post helps you nothing - yes, it gives you the answer, but you will not learn anything from it if you don't do some research...
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2010
    Posts
    1,102

    Re: Is anybody capable of providing me with guidance, not opinions?

    Sixth: you're gonna have to learn to form your own opinions eventually - it's a mighty important skill. And not just in the world of programming.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center