Saturday, August 3, 2013

Case Swiitch

******************With numbers ******************

int number;//You need this or nothing will work

            Console.WriteLine("What would you like to do?");
            Console.WriteLine("1 - Attack?");
            Console.WriteLine("2 - Run?");
            Console.WriteLine("3 - Defend?");


            number = Convert.ToInt32(Console.ReadLine());

            switch (number)
            { 
                case 1:
                    Console.WriteLine("You Attacked!");
                    break;//kicks you out of this case
                case 2:
                    Console.WriteLine("You Defended!");
                    break;
                case 3:
                    Console.WriteLine("You Ran!");
                    break;
                default:
                    Console.WriteLine("That is not a valid input");
                    break;
            }

*

Switch Statements are better to use if you know that there are going to be a limited number of answers

No comments:

Post a Comment