Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace MathQuiz
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         Random randomizer = new Random();
  16.         int addend1;
  17.         int addend2;
  18.  
  19.         int minuend;
  20.         int subtrahend;
  21.  
  22.         int multiplicand;
  23.         int multiplier;
  24.  
  25.  
  26.         int dividend;
  27.         int divisor;
  28.  
  29.         int timeLeft;
  30.  
  31.         public void StartTheQuiz()
  32.         {
  33.             addend1 = randomizer.Next(51); ;
  34.             addend2 = randomizer.Next(51); ;
  35.  
  36.             plusLeftLabel.Text = addend1.ToString();
  37.             plusRightLabel.Text = addend2.ToString();
  38.  
  39.             sum.Value = 0;
  40.             minuend = randomizer.Next(1, 101);
  41.             subtrahend = randomizer.Next(1, minuend);
  42.             minusLeftLabel.Text = minuend.ToString();
  43.             minusRightLabel.Text = subtrahend.ToString();
  44.             difference.Value = 0;
  45.  
  46.             multiplicand = randomizer.Next(2, 11);
  47.             multiplier = randomizer.Next(2, 11);
  48.             timesLeftLabel.Text = multiplicand.ToString();
  49.             timesRightLabel.Text = multiplier.ToString();
  50.             product.Value = 0;
  51.  
  52.             divisor = randomizer.Next(2, 11);
  53.             int temporaryQuotient = randomizer.Next(2, 11);
  54.             dividend = divisor * temporaryQuotient;
  55.             dividedLeftLabel.Text = dividend.ToString();
  56.             dividedRightLabel.Text = divisor.ToString();
  57.             quotient.Value = 0;
  58.  
  59.             timeLeft = 30;
  60.             timeLabel.Text = "30 seconds";
  61.             timer1.Start();
  62.  
  63.         }
  64.         public Form1()
  65.         {
  66.             InitializeComponent();
  67.         }
  68.  
  69.         private void timeLabel_Click(object sender, EventArgs e)
  70.         {
  71.  
  72.         }
  73.  
  74.         private void label1_Click(object sender, EventArgs e)
  75.         {
  76.  
  77.         }
  78.  
  79.         private void startButton_Click(object sender, EventArgs e)
  80.         {
  81.             StartTheQuiz();
  82.             startButton.Enabled = false;
  83.         }
  84.  
  85.         private bool CheckTheAnswer()
  86.         {
  87.             if ((addend1 + addend2 == sum.Value) && (minuend - subtrahend == difference.Value)
  88.                 && (multiplicand * multiplier == product.Value) && (dividend / divisor == quotient.Value))
  89.                 return true;
  90.             else
  91.                 return false;
  92.  
  93.         }
  94.  
  95.         private void timer1_Tick(object sender, EventArgs e)
  96.         {
  97.             if (CheckTheAnswer())
  98.             {
  99.  
  100.                 timer1.Stop();
  101.                 MessageBox.Show("You got all the answers right!",
  102.                                 "Congratulations!");
  103.                 startButton.Enabled = true;
  104.             }
  105.             else if (timeLeft > 0)
  106.             {
  107.  
  108.                 timeLeft--;
  109.                 timeLabel.Text = timeLeft + " seconds";
  110.             }
  111.             else
  112.             {
  113.  
  114.                 timer1.Stop();
  115.                 timeLabel.Text = "Time's up!";
  116.                 MessageBox.Show("You didn't finish in time.", "Sorry");
  117.                 sum.Value = addend1 + addend2;
  118.                 difference.Value = minuend - subtrahend;
  119.                 product.Value = multiplicand * multiplier;
  120.                 quotient.Value = dividend / divisor;
  121.                 startButton.Enabled = true;
  122.             }
  123.         }
  124.  
  125.         private void answer_Enter(object sender, EventArgs e)
  126.         {
  127.             NumericUpDown answerBox = sender as NumericUpDown;
  128.  
  129.             if (answerBox != null)
  130.             {
  131.                 int lengthOfAnswer = answerBox.Value.ToString().Length;
  132.                 answerBox.Select(0, lengthOfAnswer);
  133.             }
  134.  
  135.         }
  136.  
  137.         private void difference_ValueChanged(object sender, EventArgs e)
  138.         {
  139.  
  140.         }
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement