using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 四則運算
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int right = 0;//正确的題目個數
public static int mistake =0;//錯誤的題目個數
//随機産生的随機數0-10
private void RandomNum()
{
Random ran = new Random();
int n1, n2;
n1 = ran.Next(0, 11);
n2 = ran.Next(0, 11);
textBox1.Text = n1.ToString();
textBox2.Text = n2.ToString();
textBox3.Text = "";
}
public static int sum;
//調換四則運算的方法
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox3.Focus();
string str = comboBox1.SelectedItem.ToString();
RandomNum();
switch (str)
{
case "+":
sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
break;
case "-":
sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
break;
case "*":
sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
break;
case "/":
sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
break;
}
}
//題目的正确個數的題目的錯誤個數
private void button3_Click(object sender, EventArgs e)
{
textBox3.Focus();
RandomNum();
if(textBox3.Text == sum.ToString())
{
right++;
RandomNum();
}
else
{
mistake++;
RandomNum();
}
}
private void button1_Click(object sender, EventArgs e)
{
textBox4.Text = right.ToString();
textBox5.Text = mistake.ToString() ;
}
}
}
求助:助教你幫我看看我的代碼哪裡出錯了,我感覺我的思路是對的啊,但是最後正确的題數和錯誤的題數結果不正确。
Psp分析:
psp | Personal | Software | Process | Stages | Time |
planning | 計劃 | 15(m) | |||
Estimate | 估計這個任務需要多長時間 | 1(h) | |||
Development | 開發 | 2(h) | |||
Analysis | 需求分析 | 30(m) | |||
Design Review | 設計複審 | 40(m) | |||
Design | 具體設計 | 20(m) | |||
Code review | 代碼複審 | 10(m) | |||
Coding | 具體編碼 | ||||
Test | 測試 | 1(m) |