| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 558 人关注过本帖
标题:怎样对下面计算器进行改进,使其可以进行连续的整数加减乘除运算
只看楼主 加入收藏
lzt0814112
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-11-24
收藏
 问题点数:0 回复次数:1 
怎样对下面计算器进行改进,使其可以进行连续的整数加减乘除运算




这是简易的计算器的winform程序代码
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        char flag;

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text += button1.Text.Trim();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text += button2.Text.Trim();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text += button3.Text.Trim();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Text += button4.Text.Trim();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text += button5.Text.Trim();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            textBox1.Text += button6.Text.Trim();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            textBox1.Text += button7.Text.Trim();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            textBox1.Text += button8.Text.Trim();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            textBox1.Text += button9.Text.Trim();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            textBox1.Text += button10.Text.Trim();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            textBox1.Text += button11.Text.Trim();
        }

        private void button12_Click(object sender, EventArgs e)
        {

        }

        private void button13_Click(object sender, EventArgs e)
        {
            textBox1.Text += button13.Text.Trim();
            flag = '+';
        }

        private void button14_Click(object sender, EventArgs e)
        {
            textBox1.Text += button14.Text.Trim();
            flag = '-';
        }

        private void button15_Click(object sender, EventArgs e)
        {
            textBox1.Text += button15.Text.Trim();
            flag = '*';
        }

        private void button16_Click(object sender, EventArgs e)
        {
            textBox1.Text += button16.Text.Trim();
            flag = '/';
        }

        private void button17_Click(object sender, EventArgs e)
        {
            string s = textBox1.Text.Trim();
            textBox1.Text = "";
            char [] splitchar = {'+','-','*','/'};
            string [] nums = s.Split(splitchar);
            int [] numbers = new int [nums.Length];
            int i = 0;
            double result = 0;
            foreach(string m in nums)
            {
                numbers[i] = Convert.ToInt32(nums[i]);
                i++;
            }
            switch (flag)
            {
                case '+': result = numbers[0] + numbers[1]; break;
                case '-': result = numbers[0] - numbers[1]; break;
                case '*': result = numbers[0] * numbers[1]; break;
                case '/':
                    try
                    {
                        result = numbers[0] / numbers[1];
                    }
                    catch(DivideByZeroException)
                    {
                        MessageBox.Show("除数不能为0");
                    }
                    break;
            }
            textBox1.Text = result.ToString();
        }
    }
}

搜索更多相关主题的帖子: 计算器 private public 
2013-12-01 09:59
yangyangyixu
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-6-12
收藏
得分:0 
这个计算器太简单,实现不了连续的四则运算也没有括号
2014-06-12 14:39
快速回复:怎样对下面计算器进行改进,使其可以进行连续的整数加减乘除运算
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.077322 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved