Quantcast

Maximum PC

It is currently Sat Dec 27, 2014 5:53 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 18 posts ] 
Author Message
 Post subject: C# using console.readline() method beginner level question
PostPosted: Sun Jul 24, 2011 4:51 pm 
Little Foot
Little Foot

Joined: Tue Apr 22, 2008 9:24 am
Posts: 126
C# using console.readline() method beginner level?
Hi, folks, getting my feet wet trying to learn c# and I"m trying to create a console based simple application that will accept commands and return results. here is my code so far:

Code:
static void Main(string[] args)
{
Console.WriteLine(System.DateTime.Now);
Console.WriteLine(System.Environment.Mac…
Console.WriteLine("Hello {0} what would you like to know", System.Environment.UserName);
Console.WriteLine("type HELP for help");


I want to try putting
Code:
string name;
name = Console.ReadLine();
            if Console.ReadLine("System");
                Console.WriteLine(System.Environment.OSVersion);

But I don't think i'm going in the right direction.
I shouldn't even need to create a variable for this correct?


how can I get console.readline() to accept text and return results? i'd like to get HELP to list all the commands users can put in there.


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Mon Jul 25, 2011 3:41 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 987
Location: Earth
xs0u1x wrote:
I want to try putting
string name;
name = Console.ReadLine();
if Console.ReadLine("System");
Console.WriteLine(System.Environment.OSVersion);

But I don't think i'm going in the right direction.
I shouldn't even need to create a variable for this correct?

how can I get console.readline() to accept text and return results? i'd like to get HELP to list all the commands users can put in there.


your if statement looks wonky:

Code:
static void Main(string[] args)
{
Console.WriteLine(System.DateTime.Now);
Console.WriteLine(System.Environment.Mac…
Console.WriteLine("Hello {0} what would you like to know", System.Environment.UserName);
Console.WriteLine("type HELP for help");
string name = Console.ReadLine();
if (name.ToUpper() == "SYSTEM")
   Console.WriteLine("OS Version {0}.", System.Environment.OSVersion.VersionString);
else if (name.ToUpper() == "HELP") {
   //... do stuff
}
}


You need to assign the value being returned by Console.ReadLine() to a variable, otherwise, it's returning a value to nowhere.


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Mon Jul 25, 2011 6:29 am 
Little Foot
Little Foot

Joined: Tue Apr 22, 2008 9:24 am
Posts: 126
DJSPIN80 wrote:
xs0u1x wrote:
Code:
static void Main(string[] args)
{
Console.WriteLine(System.DateTime.Now);
Console.WriteLine(System.Environment.Mac…
Console.WriteLine("Hello {0} what would you like to know", System.Environment.UserName);
Console.WriteLine("type HELP for help");
string name = Console.ReadLine();
if (name.ToUpper() == "SYSTEM")
Console.WriteLine("OS Version {0}.", System.Environment.OSVersion.VersionString);
else if (name.ToUpper() == "HELP") {
//... do stuff
}
}


You need to assign the value being returned by Console.ReadLine() to a variable, otherwise, it's returning a value to nowhere.


thank you for the help. see exactly where I was messing up at :)


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Fri Jul 29, 2011 2:27 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Hi xs0u1x,

You'll notice that DJSpin80 used code tags with his code. I've edited your original post, but we'd appreciate it if you were to do it in the future. It makes it much easier for people to follow your code and keeps the forums looking quite a bit nicer.

And welcome to our corner of the forum. =)

Wow... the C# guys already have you doing data entry. Don't worry, they'll have you doing database queries (ie remote data entry) in a jiffy! =)
Code:
CL-USER> (dolist (item (list #'get-universal-time
              #'lisp-implementation-type
              #'lisp-implementation-version
              #'machine-version
              #'software-version))
      (print (funcall item)))

3520923881
"CLISP"
"2.37 (2006-01-02) (built on winsteingoldlap.bluelnk.net [192.168.7.100])"
"PC/686"
"GNU C 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)"


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Fri Jul 29, 2011 2:36 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
DJSPIN80 wrote:
You need to assign the value being returned by Console.ReadLine() to a variable, otherwise, it's returning a value to nowhere.

I bet you can figure out a way for him to retrieve it from the garbage collector! =)

Just for kicks, what sort of environment info does Ruby spit out? Does it use a REPL like construct like Lisp?
(REPL = read evaluate print loop)

Can you do a simple REPL inside the REPL like this...
Code:
CL-USER> (eval (read))
(+ 1 2 3)                                  <== my input
6
CL-USER> (loop for in = (read)
          until (equal in 'quit)
          do (format t "~a~%" (eval in)))
(+ 2 3)                                  <== my input
5
(* 5 6)                                  <== my input
30
quit                                  <== my input
NIL
CL-USER>


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Fri Jul 29, 2011 5:00 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 987
Location: Earth
Gadget wrote:
DJSPIN80 wrote:
You need to assign the value being returned by Console.ReadLine() to a variable, otherwise, it's returning a value to nowhere.

I bet you can figure out a way for him to retrieve it from the garbage collector! =)

Just for kicks, what sort of environment info does Ruby spit out? Does it use a REPL like construct like Lisp?
]


Honestly, I haven't gotten to that part of the book yet. ;) I'm kind of behind on my ruby reading, I think it's time for me to catch up!

He could get it from GC, but that's a WHOLE 'nother topic. I'm actually curious as to how I would be able to do so. ;)


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Fri Jul 29, 2011 4:23 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
DJSPIN80 wrote:
He could get it from GC, but that's a WHOLE 'nother topic. I'm actually curious as to how I would be able to do so. ;)

Yeah, I guess that is a pretty big jump in complexity. =)

The short answer is that you can't be assured of recovering a value before it is reclaimed by the garbage collector. However, in some interactive languages there is a facility for "reusing" a form or value. In the Lisp REPL, the last form is assigned to + and the last value to * (There are separate namespaces for functions and symbols in CL btw). This can go back three levels, so technically, it isn't possible for the garbage collector to reclaim a form or value until four forms or values later. This doesn't really have anything to do with gc per se; It is just a handy thing to have available when doing interactive programming.

I can't remember what this is called... damn, must be getting old, but I suspect there might be a similar feature in the Ruby read-eval loop.
Code:
CL-USER> (read)
"not assigned!"  <== I typed this in
"not assigned!"  <== The repl returned this value
CL-USER> *      <== reproduces the last value
"not assigned!" 
CL-USER> ++   <== reproduces the 2nd to last form used... the last form would be the *
(READ)
CL-USER> *      <== the ++ returned (read) so * now also returns (read)
(READ)


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Fri Jul 29, 2011 5:25 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
xs0u1x -- I forgot to mention what I think is one of the best write ups on learning how to program. It is Teach Yourself Programming in TEN Years by Peter Norvig, who is the current director of research at Google. One of the best things about the article is that there isn't even a single line of code! It is a must read item if you want to really improve as a programmer.

Peter Norvig wrote:
The key is deliberative practice: not just doing it again and again, but challenging yourself with a task that is just beyond your current ability, trying it, analyzing your performance while and after doing it, and correcting any mistakes. Then repeat. And repeat again. There appear to be no real shortcuts: even Mozart, who was a musical prodigy at age 4, took 13 more years before he began to produce world-class music.

One of the best places for programmers to perform this "deliberative practice" is at TopCoder. Initially, You'll be in pretty far over your head, but stick to the level 2 easy problems and before long, you'll have a decent understanding of the language and libraries. You'll have solutions that you can use as a guide and will benefit from their automated testing when you've done something wrong (and you'll be amazed at all the different ways a seemingly simple problem can fail!). Soon you'll be ready to start tackling tougher problems that will require you to learn about algorithms and data structures. It is a great resource -- take advantage of it!


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Wed Aug 03, 2011 6:29 pm 
Little Foot
Little Foot

Joined: Tue Apr 22, 2008 9:24 am
Posts: 126
Gadget wrote:
xs0u1x -- I forgot to mention what I think is one of the best write ups on learning how to program. It is Teach Yourself Programming in TEN Years by Peter Norvig, who is the current director of research at Google. One of the best things about the article is that there isn't even a single line of code! It is a must read item if you want to really improve as a programmer.
!



Thank you for the tips gentleman. Just ordered the book 10 minutes ago lol. I will definitely be visiting this forum more often.


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Thu Aug 04, 2011 7:09 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 987
Location: Earth
xs0u1x wrote:
Thank you for the tips gentleman. Just ordered the book 10 minutes ago lol. I will definitely be visiting this forum more often.


Glad we can help! :D

Myself and Crash are the resident C# guys, Gadget's the resident...uh, not sure what he's a resident of. ;) I guess he's our resident LISP guy. :P

Just remember, we won't solve your homework for you but we can help guide you through it. Post what code you've got, and we'll give you tips. :)

That reminds me, crap, I need to start posting more "Philosophy of Computer Science" stuff (i.e., hardcore dev stuff).


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Thu Aug 04, 2011 8:55 am 
Little Foot
Little Foot

Joined: Tue Apr 22, 2008 9:24 am
Posts: 126
DJSPIN80 wrote:
xs0u1x wrote:
Thank you for the tips gentleman. Just ordered the book 10 minutes ago lol. I will definitely be visiting this forum more often.


Glad we can help! :D

Myself and Crash are the resident C# guys, Gadget's the resident...uh, not sure what he's a resident of. ;) I guess he's our resident LISP guy. :P

Just remember, we won't solve your homework for you but we can help guide you through it. Post what code you've got, and we'll give you tips. :)

That reminds me, crap, I need to start posting more "Philosophy of Computer Science" stuff (i.e., hardcore dev stuff).


funny you mention homework I actually just started school for an associates specializing in programming. but I haven't made it to the more interesting(programming related) classes yet.

Assuming you guys hold real world development jobs, what are the jobs like? as in, is your code peer reviewed alot and do you get alot of micromanagement on your postion? or do you get alittle bit of freedom as a developer? I have an IT background and currently work in IT, but I think development is the next step for me in my career as i'm looking to move on from tech support.


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Thu Aug 04, 2011 3:57 pm 
Million Club - 5 Plus*
Million Club - 5 Plus*
User avatar

Joined: Sun Sep 12, 2004 6:37 pm
Posts: 4745
Location: In the monkey's litterbox
xs0u1x wrote:
Assuming you guys hold real world development jobs, what are the jobs like? as in, is your code peer reviewed alot and do you get alot of micromanagement on your postion? or do you get alittle bit of freedom as a developer? I have an IT background and currently work in IT, but I think development is the next step for me in my career as i'm looking to move on from tech support.


It really does vary from company to company on every point listed.


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Fri Aug 05, 2011 6:33 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 987
Location: Earth
Quote:
funny you mention homework I actually just started school for an associates specializing in programming. but I haven't made it to the more interesting(programming related) classes yet.


Sweet! Good luck with that! :D One thing Crash, myself and Gadget will agree on: challenge yourself, look at TopCoder stuff, even if it's the easy ones. :)

Quote:
Assuming you guys hold real world development jobs, what are the jobs like? as in, is your code peer reviewed alot and do you get alot of micromanagement on your postion? or do you get alittle bit of freedom as a developer? I have an IT background and currently work in IT, but I think development is the next step for me in my career as i'm looking to move on from tech support.


Depends on the company. I'm one of one .NET developers in my company. The company culture determines a LOT of things. I have a few friends in startups where they work hard and play hard. They have office games, happy hours, you can bring your dog into work...but they work 12 hour days. I work a VERY predictable 8-hour days (40 hour weeks). When I worked at a big bank, my code was peer reviewed a lot. We wrote gobs of documentation, and I was micromanaged a lot. Now, where I am, my boss trusts that my decisions reflects the overall team goal. I meet with my boss twice a month, at best. I get a LOT of freedom, so as long as I get my work done and I communicate things to my boss. Otherwise, the company culture will dictate it.

Honestly though, I love it. I wouldn't trade my job for anything. Developers worldwide - open source or not - have one thing in common: you gotta love this stuff. You gotta love the challenge, otherwise, you'll honestly fail. You'll need to learn to embrace constraints and limitations, because 99% of the time, you're working with it. But you also gotta embrace other platforms and languages. The one advice I'll give you before you join the wonderful world of developers: find a user group in your area that focuses on what language you want to learn and stick with them. Talk to them, hack with them (in a good way), and learn from them. You'd be surprised what you can learn from them, and how a network of other developers can benefit you.


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Tue Aug 09, 2011 7:11 pm 
Little Foot
Little Foot

Joined: Tue Apr 22, 2008 9:24 am
Posts: 126
I was poking around that TopCoder site and I don't quite get what you mean when you say "level 2 assignments" I've been looking specifically for that and can't seem to find anything. Do I need to register for this?


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Thu Aug 11, 2011 3:55 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 987
Location: Earth
xs0u1x wrote:
I was poking around that TopCoder site and I don't quite get what you mean when you say "level 2 assignments" I've been looking specifically for that and can't seem to find anything. Do I need to register for this?


Yes you do need to register. I'm not on my home PC, so I don't have access to TopCoder (unfortunately, work blocks a lot of what I like to go to, which sucks).

However, one place I go often is Code Kata. They have a lot of great reads and articles, plus programming exercises! It's very metaphysical, so be prepared to think rather than code. It's the kind of stuff that hones developer prowess.


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Thu Aug 18, 2011 12:31 pm 
Little Foot
Little Foot

Joined: Tue Apr 22, 2008 9:24 am
Posts: 126
I have found an invaluable resource I'd like to share with other noobs here but I'm not quite sure where to post it.

http://www.homeandlearn.co.uk/csharp/csharp.html


this site has helped tremendously.


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Fri Aug 19, 2011 12:28 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
xs0u1x wrote:
DJSPIN80 wrote:
xs0u1x wrote:
Thank you for the tips gentleman. Just ordered the book 10 minutes ago lol. I will definitely be visiting this forum more often.
Assuming you guys hold real world development jobs, what are the jobs like? as in, is your code peer reviewed alot and do you get alot of micromanagement on your postion? or do you get alittle bit of freedom as a developer?

It varies considerably... In general, academia/academics have a ton of freedom. Defense company jobs have tons of bosses (think Office Space, but most of the bosses are actually dumber). Software companies have varied the most in my experience. It would be kind of interesting to make a multi-dimensional plot of the various cultural/work 'factors', for lack of a better term, and see how different companies and industries cluster.


Top
  Profile  
 
 Post subject: Re: C# using console.readline() method beginner level questi
PostPosted: Fri Aug 19, 2011 1:02 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
xs0u1x wrote:
I was poking around that TopCoder site and I don't quite get what you mean when you say "level 2 assignments" I've been looking specifically for that and can't seem to find anything. Do I need to register for this?

Unfortunately, their business goals/operations have made it harder and harder to just find "programming problems" on the site during the past couple of years. After registering, go directly to http://www.topcoder.com/tc and use the menu on the left side to navigate around the site. There are a few different types of competitions, but being a beginner, I would recommend just working through the algorithm problems during the Single Round Matches (SRMs). SRMs have two divisions with Division 1 problems being harder than Division 2 problems (and the competitors considerably more experienced). Each division is given three problems to solve during the contest, followed by a challenge section (where you try to find errors in code submitted by other people), then a final point tally. Your score is based on how quickly you correctly solve problems relative to the other people in your division. Often the Division 1 easy problem is either the hard or intermediate problem for Division 2. The site accepts submissions in C++, Java, C# and VB. During the Google Code Jam, you can also submit in Python (I have no idea why they don't offer Python throughout the year during the regular contests). SRM problems are a good start, but after you've had some CS courses, you might find the Marathon Match problems more to you liking... the CS theory necessary for these problems is going to be way over your head at the moment though.

The algorithm tutorials are here.

The SRM Problem Archive

Here is a fairly typical Div 2, Level 1 problem (ie easy problem) -- Mostly just simple string and array manipulation
http://community.topcoder.com/stat?c=pr ... 9&rd=14538

This Div 2 Level 3 problem will actually make you think for a bit; Don't bother trying to implement a solution until you've spent plenty of time solving it using a whiteboard or scratch paper. You can find the overall success rate of the problem in the second URL below. Only 3% of the Division 2 competitors successfully solved the problem; The best time was just under 12 minutes.
http://community.topcoder.com/stat?c=pr ... 1&rd=14538
http://community.topcoder.com/tc?module ... 8&pm=11501


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.