Esempio n. 1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the FLASH CARD quiz");
            FlashCard quiz = new FlashCard();

            Console.Write("Please select an operation (+, -, * or /)? ");
            quiz.Op = Console.ReadLine();
            Console.WriteLine("To exit the quiz enter a blank answer.");
            bool playing = true;

            while (playing)
            {
                string equation = quiz.BuildEquation();
                Console.Write(equation);
                string temp = Console.ReadLine();
                if (temp.Length == 0)
                {
                    playing = false;
                }
                else
                {
                    double answer = double.Parse(temp);
                    if (quiz.CheckAnswer(answer) == true)
                    {
                        Console.WriteLine("CORRECT");
                    }
                    else
                    {
                        Console.WriteLine("INCORRECT");
                    }
                }
            }
        }
Esempio n. 2
0
        protected void btnAnswer_Click(object sender, EventArgs e)
        {
            if (txtAnswer.Text.Trim().Length == 0)
            {
                lblCorrect.Text = "Please enter an answer.";
                return;
            }
            double answer = double.Parse(txtAnswer.Text);

            try
            {
                if (quiz.CheckAnswer(answer) == true)
                {
                    lblCorrect.Text = "Correct";
                    user.Correct++;
                    db.SaveChanges();
                }
                else
                {
                    lblCorrect.Text = "Incorrect";
                }
                lblCorrect.Text = lblCorrect.Text + " - " + user.Correct + " correct out of " + user.Tries + " tries";
            }
            catch (Exception ex)
            {
                lblCorrect.Text = ex.Message;
            }
            btnQuestion.Enabled = true;
            btnAnswer.Enabled   = false;
        }