Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > learning to code - question on dictionary example

Reply
Thread Tools

learning to code - question on dictionary example

 
 
Learning to code
Guest
Posts: n/a
 
      11-27-2011
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();
}
}
}
 
Reply With Quote
 
 
 
 
Learning to code
Guest
Posts: n/a
 
      11-27-2011
thank you! I removed the incorrect post as well.
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      11-29-2011
Learning to code <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
tom st denis
Guest
Posts: n/a
 
      11-29-2011
On Nov 28, 7:24*pm, Keith Thompson <(E-Mail Removed)> wrote:
> Learning to code <(E-Mail Removed)> 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
 
Reply With Quote
 
Geoff
Guest
Posts: n/a
 
      11-29-2011
On Mon, 28 Nov 2011 17:08:42 -0800 (PST), tom st denis <(E-Mail Removed)>
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?
 
Reply With Quote
 
Patrick Scheible
Guest
Posts: n/a
 
      11-29-2011
tom st denis <(E-Mail Removed)> writes:

> On Nov 28, 7:24*pm, Keith Thompson <(E-Mail Removed)> wrote:
>> Learning to code <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance ordered dictionary vs normal dictionary Navkirat Singh Python 6 07-29-2010 10:18 AM
Re: Performance ordered dictionary vs normal dictionary Chris Rebert Python 0 07-29-2010 06:11 AM
creating a dictionary from a dictionary with regex james_027 Python 1 08-22-2007 07:39 AM
[DICTIONARY] - Copy dictionary entries to attributes Ilias Lazaridis Python 6 02-21-2006 11:27 AM
dictionary within dictionary Fox ASP General 5 03-13-2005 05:03 AM



Advertisments