static void Main(string[] args) { Console.Write("Enter the number of cards to pick: "); //assigns the user input to a string variable string line = Console.ReadLine(); //if user input can be converted to int then do the following.. if (int.TryParse(line, out int numberCards)) { //My own solution (the solution from the book was simpler): //string[] results = CardPicker.PickSomeCards(numberOfCards); //int count = 0; //calling the PickSomeCards method, and inputting the user input foreach (string card in CardPicker.PickSomeCards(numberCards)) { Console.WriteLine(card); //Console.WriteLine(results[count]); //count++; } } else { Console.WriteLine("You must type a number!"); } }
static void Main(string[] args) { Console.Write("Enter number of cards to pick: "); string line = Console.ReadLine(); if (int.TryParse(line, out int numberOfCards)) { foreach (string card in CardPicker.PickSomeCards(numberOfCards)) { Console.WriteLine(card); } } else { Console.WriteLine("Please enter a valid number"); } }
static void Main(string[] args) { Console.Write("Hello, please enter the number of cards to pick: "); string input = Console.ReadLine(); // Check if the input is a INT variable. if (int.TryParse(input, out int numberOfCards)) { foreach (string card in CardPicker.PickSomeCards(numberOfCards)) { Console.WriteLine(card); } } else { Console.WriteLine("Please enter a valid number."); } }
static void Main(string[] args) { Console.WriteLine("Please, enter the number of cards"); string line = Console.ReadLine(); if (int.TryParse(line, out int numberOfCards)) { CardPicker.PickSomeCards(numberOfCards); foreach (string card in CardPicker.PickSomeCards(numberOfCards)) { Console.WriteLine(card); } } else { Console.WriteLine("F**k you, wrong stuff"); } }
static void Main(string[] args) { Write("Please enter the number of cards: "); string rawInput = ReadLine(); if (int.TryParse(rawInput, out int numberOfCards)) { string[] cardsPicked = CardPicker.PickSomeCards(numberOfCards); foreach (var card in cardsPicked) { WriteLine(card); } } else { WriteLine($"Error the value provided, {rawInput} was not a valid number!"); } }
static void Main() { Console.Write("Enter the number of cards to pick: "); string line = Console.ReadLine(); if (int.TryParse(line, out int numberOfCards)) { string[] result = CardPicker.PickSomeCards(numberOfCards); foreach (string card in result) { Console.WriteLine(card); } } else { Console.WriteLine("Not a vaild number..."); Main(); } }
static void Main(string[] args) { Console.Write("Enter the number of cards to pick: "); string line = Console.ReadLine(); if (int.TryParse(line, out int numberOfCards)) { // this block is executed if line COULD be converted to an int // value that's stored in a new variable called numberOfCards string[] cards = CardPicker.PickSomeCards(numberOfCards); foreach (string card in cards) { Console.WriteLine(card); } } else { // this block is executed if line COULD NOT be converted to an int Console.WriteLine("Not a valid number."); } }