天天看点

四则运算

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)

  

四则运算
下一篇: 对git的认识