Ejemplo n.º 1
0
        private static void Run()
        {
            int    numCorrect = 0;
            double result;
            double answer;
            int    numProbs = 0;
            double total    = 0;

            try
            {
                Console.WriteLine($"Welcome to Math Practice!\n\n{MainMenu()}");
                switch (Console.ReadLine())
                {
                case "1":     // Additon
                    numProbs = NumOfProbsPrompt();
                    Console.WriteLine($"Here is {numProbs} addition problems!");
                    for (int i = 1; i <= numProbs; i++)
                    {
                        result = GameFunctions.Addition(i);
                        answer = GetUserAnswer(ref numCorrect, result);
                    }
                    total = CalcScore(numCorrect, numProbs);
                    break;

                case "2":     // Subtraction
                    numProbs = NumOfProbsPrompt();
                    Console.WriteLine($"Here is {numProbs} subtraction problems!");
                    for (int i = 1; i <= numProbs; i++)
                    {
                        result = GameFunctions.Subtraction(i);
                        answer = GetUserAnswer(ref numCorrect, result);
                    }
                    total = CalcScore(numCorrect, numProbs);
                    break;

                case "3":     // Multiplication
                    numProbs = NumOfProbsPrompt();
                    Console.WriteLine($"Here is {numProbs} multiplication problems!");
                    for (int i = 1; i <= numProbs; i++)
                    {
                        result = GameFunctions.Multiplication(i);
                        answer = GetUserAnswer(ref numCorrect, result);
                    }
                    total = CalcScore(numCorrect, numProbs);
                    break;

                case "4":     // Divison (100ths place)
                    Console.WriteLine($"Here is {numProbs} Divison (roundeed to the 100ths place) problems!");
                    numProbs = NumOfProbsPrompt();
                    for (int i = 1; i <= numProbs; i++)
                    {
                        result = GameFunctions.Division(i);
                        answer = GetUserAnswer(ref numCorrect, result);
                    }
                    total = CalcScore(numCorrect, numProbs);
                    break;

                case "0":
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Please enter a valid option.");
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ForegroundColor = ConsoleColor.White;
            }
            finally
            {
                Console.ReadLine();
                Console.Clear();
                Run();
            }
        }