其他分享
首页 > 其他分享> > 计应191(西)申振翔 口算题卡

计应191(西)申振翔 口算题卡

作者:互联网

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 WindowsFormsApp5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int a, b;
string op;
double result;
Random rnd = new Random();

private void button2_Click(object sender, EventArgs e)
{
string str = txtAnswer.Text;
double d = double.Parse(str);
string disp = " " + a + op + b + "=" + str + " ";
if (d == result)
disp += "√";
else
disp += "x";
listBox1.Items.Add(disp); //在list中输出
}

private void button1_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 = (int)(((double)a / b)*100)*1.0/100; break; //保留两位小数
}
label1.Text = a.ToString();
label2.Text = op;
label3.Text = b.ToString();
txtAnswer.Text = " "; //输出随机题目

}
}
}

标签:result,disp,Text,191,System,计应,using,算题,op
来源: https://www.cnblogs.com/jyzj/p/14833639.html