jeudi 22 novembre 2018

Randomly assign array value with another array's value

I'm emulating a Deal or No Deal game where the user chooses a case from a specified list. Now, on each run of the console app I want there to be a random assignment for each cash prize to each case (for fairness sakes). My code is of the following:

    int[] cashPrizeArray = new int[] { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
    string[] caseArray = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

    Console.WriteLine("Deal or Not!");
    Console.Write("Choose a case: 1-26: ");
    string userCase = Console.ReadLine();



    if (!caseArray.Contains(userCase))
    {
        Console.WriteLine("\nUnexpected input text.\nThis application will now be terminated.\nPress ENTER to continue...");
        Console.ReadLine();
        Environment.Exit(0);
    }

    else
    {
        Console.WriteLine("You chose case " + userCase);
        Console.ReadLine();
    }

I will need to reference these cases one by one when a user chooses them, and then remove them from being called in the array once initially opened.




Aucun commentaire:

Enregistrer un commentaire