简易计算器的实现_浪漫晨风

简易计算器的实现

    最近学习了一下c#,编写了一个功能简单的计算器,下面是我的源代码和思路,用以同大家交流。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace calculate
{
    public partial class Form1 : Form
    {
        double dbfrist;//存储{dy}个数字
        double dbsec;//存储第二个数字
        double result;//存储结果
        Char ope;//标示加减乘除
      
        public Form1()
        {
            InitializeComponent();
          
        }

        //清空按钮

      private void button22_Click(object sender, EventArgs e)
        {
            txtResult.Text = "";
        }

        //输入数字

         private void bnt1_Click(object sender, EventArgs e)
        {
            txtResult.Text = txtResult.Text + '1';
        }

。。。。。。。。

//加法     

private void bntAdd_Click(object sender, EventArgs e)

{
           
            
            dbfrist = Convert.ToDouble(txtResult.Text);
            txtResult.Text ="";
            ope = '+';

        }

...................................................................

        //处理等号

private void bntEqu_Click(object sender, EventArgs e)
        {
           
            dbsec = Convert.ToDouble(txtResult.Text);
           
            switch (ope)

            {
                case '+': result = dbfrist + dbsec; break;
                case '-': result = dbfrist - dbsec; break;
                case '*': result = dbfrist * dbsec; break;
                case '/':
                    if (dbsec == 0)
                    {
                        MessageBox.Show("除数不能为零!");
                      
                    }
                    else
                        result = dbfrist / dbsec; break;
                   
                default: break;
            
            }
            txtResult.Text = Convert.ToString(result);
          
          
        }

       



郑重声明:资讯 【简易计算器的实现_浪漫晨风】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——