Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[SOLVED] How To Grab User Input?

user input

  • This topic is locked This topic is locked
3 replies to this topic

#1 tavich

tavich

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 399 posts
  • Location:Delaware
  • Programming Language:C#
  • Learning:C++, PHP, JavaScript

Posted 19 May 2012 - 06:53 AM

I have created a simple layout in a console of a menu.
When the user enters a option, I want it to load from a if statement,
But from the option, Like if the user enters apple I would like to know howto create an if statement saying if the user typed apple then *condition

Would I have to create a variable? I don't see any useful options when coding on Visual Studio
  • 0
Send a like my way if I helped you or if you found my post useful or even just enjoyed reading my post.
Thank you :)

#2 papabear

papabear

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 472 posts
  • Location:DarkSide

Posted 19 May 2012 - 07:12 AM

Hello ThatOneGuy let me try to answer your question base on how I understand it and what the title of the thread says.
Yes you must create a variable as a reference for your if else condition.

Here's a simple example of how you can ask and get the user input

Console.WriteLine("Enter your name : ");
string s7 = Console.ReadLine();



for the control statement you can use either switch or if else.. just choose the one where you are comfortable with
here's an example after the user sends an input

if ( s7 == "Papabear" ) {
    Console.WriteLine("Hey!");
} else {
    Console.WriteLine("Hi");
}


for a good tutorial in c# try to look at this website http://www.csharp-st...m/Tutorial.aspx and this section into our forum C# Programming Tutorials

Have Fun Coding
  • 0
Life has no CTRL+Z
Never Forget To HIT "LIKE" If I Helped

#3 tavich

tavich

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 399 posts
  • Location:Delaware
  • Programming Language:C#
  • Learning:C++, PHP, JavaScript

Posted 19 May 2012 - 07:44 AM

Thanks alot!!!!
  • 0
Send a like my way if I helped you or if you found my post useful or even just enjoyed reading my post.
Thank you :)

#4 Roger

Roger

    Skadoosh!

  • Administrator
  • 1222 posts
  • Programming Language:C, PHP
  • Learning:Others

Posted 19 May 2012 - 08:07 AM

This topic has been marked as SOLVED. If you have a similar question or topic, go back to the subforum and start a new topic to continue discussions.
  • 0

New around here? Click here to register and start participating in under a minute?

Or do a quick search and you may find the answer you're looking for.






Also tagged with one or more of these keywords: user input

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download