首页 > 其他 > 详细

第一次作业:编写一个四则运算随机出题程序

时间:2018-10-10 23:17:17      阅读:201      评论:0      收藏:0      [点我收藏+]
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 出题
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int a, b, c, d;
           Random shu = new Random();
           Random fuhao = new Random();
           int shuzi1= shu.Next(10, 100);
           
           textBox1.Text=shuzi1.ToString();
           int shuzi2 = shu.Next(10, 100);//取0-100的随机数
           textBox3.Text = shuzi2.ToString();
              a=shuzi1 +shuzi2 ;
              b=shuzi1 -shuzi2 ;
              c=shuzi1 *shuzi2 ;
              d = shuzi1 / shuzi2;
            int fuhao1=fuhao.Next(1, 5);//取1-4的随机数用来对应运算符号
            //用于接受运算符号
           
            switch (fuhao1)//判断运算符号
            {
                case 1:
                    textBox2.Text = "+";
                    textBox4.Text =Convert.ToString(a);
                    break;
                case 2:
                    textBox2.Text = "-";
                   textBox4.Text=Convert.ToString(b);
                    break;
                case 3:
                    textBox2.Text =  "*";
                  textBox4.Text=Convert.ToString(c);
                    break;
                case 4:
                    textBox2.Text = "/";
                    textBox4.Text=Convert.ToString(d);
                    break;
            }
            
          //第一个运算符号

           

           
         
           

          }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {

            textBox6.Text = textBox4.Text;
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            textBox5.Focus();
        }

        private void textBox7_TextChanged(object sender, EventArgs e)
        {

        }


    }
}

技术分享图片

 

第一次作业:编写一个四则运算随机出题程序

原文:https://www.cnblogs.com/moxizi/p/9769523.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!