private static Random random = new Random();
public static void main(string[] args)
player = random.Next(2) + 1;
output("What is the maximum number of chips that can be drawn each turn?" + "\n");
tokenMax = (int) inputValue();
output("Chips left on the table: " + score + "\n");
output("How many chips do you want to take?" + "\n");
tokenTake = (int) inputValue();
while (tokenTake > tokenMax)
output("You can only take between 1 and " + tokenMax + " chips. Try again." + "\n");
tokenTake = (int) inputValue();
score = score - tokenTake;
p2take = random.Next(tokenMax) + 1;
output("My turn. I'm taking " + p2take + " chip(s)." + "\n");
output("I won because of my amazing skill." + "\n");
output("You won. Lucky." + "\n");
' .NET can only read single characters or entire lines from the console.
' The following functions are designed to help input specific data types.
private static double inputValue()
while (!double.TryParse(Console.ReadLine(), out result));
private static string inputText()
return Console.ReadLine()
private static output(string text)