Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   learning to code - question on dictionary example (http://www.velocityreviews.com/forums/t806333-learning-to-code-question-on-dictionary-example.html)

Learning to code 11-27-2011 05:52 PM

learning to code - question on dictionary example
 
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 11-27-2011 06:54 PM

Re: learning to code - question on dictionary example
 
thank you! I removed the incorrect post as well.

Keith Thompson 11-29-2011 12:24 AM

Re: learning to code - question on dictionary example
 
Learning to code <ryan.morrone@gmail.com> 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) kst-u@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

tom st denis 11-29-2011 01:08 AM

Re: learning to code - question on dictionary example
 
On Nov 28, 7:24*pm, Keith Thompson <ks...@mib.org> wrote:
> Learning to code <ryan.morr...@gmail.com> 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

Geoff 11-29-2011 02:11 AM

Re: learning to code - question on dictionary example
 
On Mon, 28 Nov 2011 17:08:42 -0800 (PST), tom st denis <tom@iahu.ca>
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?

Patrick Scheible 11-29-2011 03:17 AM

Re: learning to code - question on dictionary example
 
tom st denis <tom@iahu.ca> writes:

> On Nov 28, 7:24*pm, Keith Thompson <ks...@mib.org> wrote:
>> Learning to code <ryan.morr...@gmail.com> 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


All times are GMT. The time now is 07:05 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.