| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 802 人关注过本帖
标题:热烈欢迎。《关于C#计算器地,为什么算出结果不对》
取消只看楼主 加入收藏
raojuncf
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-9-21
结帖率:0
收藏
 问题点数:0 回复次数:0 
热烈欢迎。《关于C#计算器地,为什么算出结果不对》
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 计算器
{
    public partial class Form1 : Form
    {
        
        double num1=0,num2 = 0, num3 = 0, num4=0,num5=0,num6=0;
        char a;
        public Form1()
        {
            InitializeComponent();
        }

        private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void b1_Click(object sender, EventArgs e)
        {
            
            textBox1.Text += ((Button)sender).Text;
            num1 = Double.Parse(textBox1.Text);
        }
        

        private void b13_Click(object sender, EventArgs e)
        {
            textBox1.Text = string.Empty;
            //textBox1.Text ="+";
            a = '+';
            
            

        }

        private void b14_Click(object sender, EventArgs e)
        {
            textBox1.Text = string.Empty;
            //textBox1.Text ="-";
            a = '-';
            
            
        }

        private void b15_Click(object sender, EventArgs e)
        {
            textBox1.Text = string.Empty;
            //textBox1.Text ="*";
            a = '*';
            
        }

        private void b16_Click(object sender, EventArgs e)
        {
            textBox1.Text = string.Empty;
            //textBox1.Text = "/";
            a = '/';
            
        }

        private void b12_Click(object sender, EventArgs e)
        {
            
            num2=Double.Parse(textBox1.Text);
            
            switch (a)
            {
                case '+':
                    {
                        if(num3!=0)
                         num1 = num3;
                        num3 = num1 + num2;
                        
                        textBox1.Text = num3.ToString();
                    } break;
                case '-':
                    {
                        if (num4!=0)
                         num1 = num4;
                        num4 = num1 - num2;
                        
                        textBox1.Text = num4.ToString();
                    } break;
                case '*':
                    {
                        if (num5 != 0)
                            num1 = num5;
                      num5 = num1 * num2;
                        textBox1.Text = num5.ToString();
                    } break;
                case '/':
                    {
                        if (num6 != 0)
                            num1 = num6;
                       num6 = num1 / num2;
                        textBox1.Text = num6.ToString();
                    } break;
            }
            

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            time.Text = string.Format("现在时间:  {0}", DateTime.Now);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = string.Empty;
        }

    }

      

     
}
搜索更多相关主题的帖子: 欢迎 结果 计算器 
2009-10-13 21:39
快速回复:热烈欢迎。《关于C#计算器地,为什么算出结果不对》
数据加载中...
 
   



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

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