C#:出题并判断
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test_19
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int a, b;
string op;
int result;
Random rnd = new Random();
private void btnJudge_Click(object sender, EventArgs e)
{
string str = txtResult.Text;
double d = double.Parse(str);
string disp = "" + a + op + b + "=" + str + " ";
if (d == result)
disp += "√";
else
disp += "×";
listJResult.Items.Add(disp);
}
private void btnNew_Click(object sender, EventArgs e)
{
a = rnd.Next(9) + 1;
b = rnd.Next(9) + 1;
int c = rnd.Next(4);
switch (c)
{
case 0: op = "+";result = a + b;break;
case 1: op = "-";result = a - b;break;
case 2: op = "*";result = a * b;break;
case 3 :op = "/";result = a / b;break;
}
labOne.Text = a.ToString();
labTwo.Text = b.ToString();
labFlag.Text = op;
txtResult.Text = "";
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57