| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 802 人关注过本帖
标题:热烈欢迎。《关于C#计算器地,为什么算出结果不对》
只看楼主 加入收藏
raojuncf
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-9-21
结帖率:0
收藏
 问题点数:0 回复次数:5 
热烈欢迎。《关于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
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:0 
这只是部分代码

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-10-14 08:37
dikeboy
Rank: 2
等 级:论坛游民
帖 子:54
专家分:56
注 册:2009-10-5
收藏
得分:0 
LZ的代码逻辑不对吧,我改了下,你试试


using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using
 
namespace test
{
    public partial class Form1 : Form
    {
        double num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0, num6 = 0;
        char a='c';
 
        public Form1()
        {
            InitializeComponent();
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
         
            textBox1.Clear();
            textBox1.Text += ((Button)sender).Text;
            if (a == 'c')
              num1 = Double.Parse(textBox1.Text);
            Console.WriteLine(num1);
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
        if(a!='c')
           {  
              num2 = Double.Parse(textBox1.Text);
              Console.WriteLine(num2);
              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;
            }
               }
               else
               {
                   Console .WriteLine ("DK");
               }
            a = char.Parse(((Button)sender).Text);
 
            }
 
        private void button16_Click(object sender, EventArgs e)
        {
            a='c';
            num1 = 0; num2 = 0; num3 = 0; num4 = 0;num5 = 0; num6 = 0;
            textBox1 .Text ="";
 
        }
        }
    }
 
2009-10-14 15:54
fed24
Rank: 2
来 自:成都
等 级:论坛游民
帖 子:33
专家分:27
注 册:2008-10-24
收藏
得分:0 
楼主的命名规范不好喔..
2009-10-16 10:13
NTYLWJ
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:191
专家分:698
注 册:2008-12-2
收藏
得分:0 
支持一下。以后这样的问题最后先自己调试,这样的问题用调试都可以解决的。要学会调试。
2009-10-18 14:57
wzh19890404
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2009-9-28
收藏
得分:0 
以下是引用NTYLWJ在2009-10-18 14:57:19的发言:

支持一下。以后这样的问题最后先自己调试,这样的问题用调试都可以解决的。要学会调试。
同意 我也是新手哦
2009-10-18 21:27
快速回复:热烈欢迎。《关于C#计算器地,为什么算出结果不对》
数据加载中...
 
   



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

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