Anonim_999

makaka

Dec 27th, 2022 (edited)
1,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3.  
  4. namespace WindowsFormsApp1
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.         private static int x = 0;
  9.         private static int y = 0;
  10.         private static int rightAnswer = 0;
  11.         private static int bal = 0;
  12.         private static int step = 1;
  13.  
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void Form1_Load(object sender, EventArgs e)
  20.         {
  21.             GenerateUrav(ref x, ref y, ref rightAnswer);
  22.         }
  23.  
  24.         private void GenerateUrav(ref int x, ref int y, ref int right)
  25.         {
  26.             Random random = new Random();
  27.             x = random.Next(1,21);
  28.             y = random.Next(1,21);
  29.             right = x + y;
  30.             label1.Text = $"{x} + {y} = ";
  31.         }
  32.  
  33.         private void button1_Click(object sender, EventArgs e)
  34.         {
  35.             step++;
  36.  
  37.             if (step <= 5)
  38.             {
  39.                 label2.Text = $"{step}/5";
  40.                
  41.                 if (textBox1.Text != "")
  42.                 {
  43.                     if (textBox1.Text == rightAnswer.ToString())
  44.                     {
  45.                         MessageBox.Show("Правильно!");
  46.                         bal++;
  47.                     }
  48.                     else
  49.                     {
  50.                         MessageBox.Show("Неправильно!");
  51.                     }
  52.                 }
  53.                 else
  54.                 {
  55.                     MessageBox.Show("Неправильный ввод!");
  56.                 }
  57.             }
  58.             else
  59.             {
  60.                 if (bal == 5)
  61.                     MessageBox.Show("Отлично!");
  62.                 else if (bal == 4)
  63.                     MessageBox.Show("Хорошо!");
  64.                 else if(bal == 3)
  65.                     MessageBox.Show("Удовлетворительно");
  66.                 else
  67.                     MessageBox.Show("Плохо");
  68.                 bal = 0;
  69.                 step = 1;
  70.                 label2.Text = $"{step}/5";
  71.             }
  72.             GenerateUrav(ref x, ref y, ref rightAnswer);
  73.         }
  74.     }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment