User input in C#
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
Have a look at Console.ReadLine(), it reads a line of data taken from the command line, and is terminated by the enter key.
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?
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?
You have to define a body for Main:
Magius
using System;public class Age{ public static void Main() { Console.WriteLine("Please input your age."); string line = Console.ReadLine(); }}
Magius
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement