C#加法器的问题
请问
IF(c==a+b)答对了我就加一分如何实现呢?
我用过
if(c==a+b)
{int sum;
for(n=0;n<100;n++)
sum+=n
string s=sum.TOstring();
label5.s=sum;
}
行不通!
源程序如下:
private void Form1_Load(object sender, EventArgs e)
{
int n;
Random my = new Random();
n=my.Next(5);
label1.Text = n.ToString();//为了把label1转换为字符串
n = my.Next(10);
label3.Text = n.ToString();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsDigit(e.KeyChar) == true)|| e.KeyChar == 8)
e.Handled = true;
if (e.KeyChar == 13 )
{
int n=0;
if (textBox1.Text == "")
{
MessageBox.Show("未输入答案");
return;
}
int a, b, c;
a = int.Parse(label1.Text);
b = int.Parse(label3.Text);
c = int.Parse(textBox1.Text);
if (c == a + b)
{
MessageBox.Show("真聪明答对了");
Form1_Load(null, null);//清零
textBox1.Text = "";