lundi 8 février 2016

C# Using user input to select what string array to randomly print the elements from

I'm new to coding so please excuse my terminology..

I'm trying to make a random league of legends skin selector. I want the user to input the champion they want, in this case I have ahri and leeSin, then with the user input, I want it to select the string array and randomly print one of the elements. I think I'm pretty close but I cannot use a string with a string[]. Any help would be very appreciated.

namespace RandomLolChampSelector
{
    class Program
    {
        static void Main(string[] args)

        {
            string[] ahri = { "Academy", "Challenger", "Dynasty", "Foxfire", "Midnight", "Popstar" };
            string[] leeSin = { "Traditional", "Acolyte", "Dragon Fist", "Musy Thai", "Pool Party", "SKT T1", "Knockout" };

            // Creates title for application
            Console.WriteLine("Conor's Random League of Legends Skin Selector v0.1");
            Console.WriteLine(" ");
            Console.WriteLine(" ");

            Random rnd = new Random();

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("What champion would you like to select a skin for?..    ");
            string champion = Console.ReadLine();

            foreach (string s in champion)
            {
                while (true)
                {
                    // Gets user to press a key to run the code
                    Console.Write("Press the 'enter' key for a random champion..     ");
                    string question = Console.ReadLine();

                    int randomNumber = rnd.Next(ahri.Length);
                    Console.WriteLine(ahri[randomNumber]);
                }
            }
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire