learning to code - question on dictionary example

Discussion in 'C Programming' started by Learning to code, Nov 27, 2011.

  1. Hello,

    I'm am learning to program and hoping someone could help me with my code question.

    Below I have pasted the C# dictionary code example I am working on. The intent of the program is to ask a user a question, read their response, and respond back to the user. This is a counsel application written in C#, usingthe visual studio 2010 express edition.

    Reviewing the code below, where I am stuck is on this line:

    Console.WriteLine("my response is {0}",dict[myInput]);

    What I would like the program to do is read the response the user entered, find the key within the dictionary, and respond back to the user based on the value for that key.

    I believe what is incorrect above is where I am trying to pass in the string value from the myInput variable, into the dictionary.

    If the program worked correctly - it would ask the user their name, if the user typed "tara", it would respond back "Hi Tara!" (based on the string value in the dictionary).


    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication1
    {
    public class Example
    {
    public static void Main()
    {
    // Create and initilize dictionary of strings.
    Dictionary<string, string> dict = new Dictionary<string, string>();
    dict.Add("Tara", "Hi Tara!");
    dict.Add("Ryan", "Hi Ryan!");

    //Introduction
    Console.WriteLine("What is your name?");

    //Read Answer
    String myInput = Console.ReadLine();

    //Respond
    Console.WriteLine("my response is {0}",dict[myInput]);

    //Stop
    Console.ReadLine();
    }
    }
    }
     
    Learning to code, Nov 27, 2011
    #1
    1. Advertising

  2. thank you! I removed the incorrect post as well.
     
    Learning to code, Nov 27, 2011
    #2
    1. Advertising

  3. Learning to code <> writes:
    > thank you! I removed the incorrect post as well.


    No, you didn't. You may have removed it from Google Groups, but it
    still shows up on my Usenet server. (Don't worry about it, though; just
    be aware that you can't generally delete anything you've posted to Usenet.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Nov 29, 2011
    #3
  4. Learning to code

    tom st denis Guest

    On Nov 28, 7:24 pm, Keith Thompson <> wrote:
    > Learning to code <> writes:
    >
    > > thank you!  I removed the incorrect post as well.

    >
    > No, you didn't.  You may have removed it from Google Groups, but it
    > still shows up on my Usenet server.  (Don't worry about it, though; just
    > be aware that you can't generally delete anything you've posted to Usenet..)


    It'd work if your server honoured cancel requests but since they're
    ridiculously easy to forge nobody does...

    I have to question just how naive the fathers of the Internet were...

    If people signed their posts they could sign cancel requests too ...
    but we're still decades out from implementing 1990s technology...

    Now don't get me started on why we still use "passwords" to login to
    servers...

    Tom
     
    tom st denis, Nov 29, 2011
    #4
  5. Learning to code

    Geoff Guest

    On Mon, 28 Nov 2011 17:08:42 -0800 (PST), tom st denis <>
    wrote:

    >I have to question just how naive the fathers of the Internet were...
    >


    Just read the RFC's. I can't recall a single instance of any of them
    designing-in any decent authentication mechanisms. In those days,
    everyone played by the rules and encryption was never used. To be
    fair, I don't think anyone gave much thought to built-in resistance to
    exploitation because it was all just a research tool and fun times
    between labs. All the geeks were equally baffled when the Morris worm
    emerged. How could anyone mess with their beautiful net?
     
    Geoff, Nov 29, 2011
    #5
  6. tom st denis <> writes:

    > On Nov 28, 7:24 pm, Keith Thompson <> wrote:
    >> Learning to code <> writes:
    >>
    >> > thank you!  I removed the incorrect post as well.

    >>
    >> No, you didn't.  You may have removed it from Google Groups, but it
    >> still shows up on my Usenet server.  (Don't worry about it, though; just
    >> be aware that you can't generally delete anything you've posted to Usenet.)

    >
    > It'd work if your server honoured cancel requests but since they're
    > ridiculously easy to forge nobody does...
    >
    > I have to question just how naive the fathers of the Internet were...


    There wasn't a good way to sign Usenet posts, or e-mail, that would run
    in minimal time and space on a 1970s system. Given no way to do it that
    would stop forgery, better not to do it at all so undergrads around the
    world wouldn't take it as a challenge.

    -- Patrick
     
    Patrick Scheible, Nov 29, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ilias Lazaridis
    Replies:
    6
    Views:
    463
    Ilias Lazaridis
    Feb 21, 2006
  2. Hal Vaughan
    Replies:
    7
    Views:
    509
  3. james_027
    Replies:
    1
    Views:
    348
    Marc 'BlackJack' Rintsch
    Aug 22, 2007
  4. Mathieu Blondel
    Replies:
    0
    Views:
    105
    Mathieu Blondel
    Jun 20, 2005
  5. Andrey Popp

    [I'm learning C]: Learning to use ucontext

    Andrey Popp, Jan 29, 2012, in forum: C Programming
    Replies:
    5
    Views:
    784
    Keith Thompson
    Jan 31, 2012
Loading...

Share This Page