Jump to content
  • Advertisement
Sign in to follow this  
8raker

User input in C#

This topic is 5394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have recently started c#. I love it. I used to code in basic, but now C# has incorparated the easiness of basic and some of the features of C++. I was wondering if anyone could help me with user input. I would like to create a number guessing game. Ex: Im a even number. I am between 10 and 50. I am not any 30's though. Say the number was 28. How could the user input 28? I would do something like int a = 28 (user input here) if (userinputhere is a) Console.WriteLine("You have guessed the number!") Something like that. TIA 8raker

Share this post


Link to post
Share on other sites
Advertisement
Have a look at Console.ReadLine(), it reads a line of data taken from the command line, and is terminated by the enter key.

Share this post


Link to post
Share on other sites
using System;
public class Age
{
public static void Main();

Console.WriteLine("Please input your age.")
Console.ReadLine()
}


This Is what I have. I get two errors. One on line 6, and one on line 7.

Could anyone supply a code to make an example?

Share this post


Link to post
Share on other sites
You have to define a body for Main:



using System;
public class Age
{
public static void Main()
{
Console.WriteLine("Please input your age.");
string line = Console.ReadLine();
}
}



Magius

Share this post


Link to post
Share on other sites
Thanks a bunch Mag!
One last question. How could I make it so if you say your 21 then It would say "You can drink beer!" and like if your 18 "You can smoke" and etc.?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!