Ejemplo n.º 1
0
        // enum metod som kollar om användarens input stämmer med alternativen som finns
        // om inputen stämmer convertas den och skickas vidare
        private enumChooseTypeOfGoalMenu enumChooseTypeOfGoalMenuTryCatch()
        {
            do
            {
                try
                {
                    Console.WriteLine("1 | Set Distance Goal");
                    Console.WriteLine("2 | Set Time Goal");
                    Console.Write("Choice: ");

                    int userInput = Convert.ToInt32(Console.ReadLine());

                    if (userInput > 2 || userInput < 1)
                    {
                        Console.Clear();
                        throw new Exception();
                    }
                    enumChooseTypeOfGoalMenu choice = (enumChooseTypeOfGoalMenu)userInput;
                    return(choice);
                }
                catch
                {
                    Console.WriteLine("1-2 only");
                    Console.ReadLine();
                }
            } while (true);
        }
Ejemplo n.º 2
0
        // tar input från användaren och kollar så den stämmer med de alternativ som finns
        private enumChooseTypeOfGoalMenu ChooseTypeOfGoal()
        {
            enumChooseTypeOfGoalMenu choice = enumChooseTypeOfGoalMenuTryCatch();

            switch (choice)
            {
            case enumChooseTypeOfGoalMenu.setDistanceGoal:
                Menu.enumSportMenu choice1 = enumTryCatchForSportMenu();
                ChooseSportForDistanceGoal(choice1);
                return(choice);

            case enumChooseTypeOfGoalMenu.setTimeGoal:
                Menu.enumSportMenu choice2 = enumTryCatchForSportMenu();
                ChooseSportForTimeGoal(choice2);
                return(choice);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }