| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1692 人关注过本帖
标题:我是初学者 做了个计算器 可是计算有问题麻烦各位前辈帮下忙 看看错误在哪 ...
只看楼主 加入收藏
南风萧萧
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-12-14
收藏
 问题点数:0 回复次数:6 
我是初学者 做了个计算器 可是计算有问题麻烦各位前辈帮下忙 看看错误在哪要怎么改 谢谢
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {

        static double x1, x2;
        double x;
        string c;

        public Form1()
        {
            InitializeComponent();

        }
        private void sz_button(int n)
        {
            if (c == null) x1 = x1 * 10 + n;
            else x2 = x2 * 10 + n;
            textBox1.Text += n;
        }
        private void ysf_button(string m)
        {
            c = m;
            textBox1.Text += m;
        }
        private void button11_Click(object sender, EventArgs e)
        {
            sz_button(1);
        }

        private void button12_Click(object sender, EventArgs e)
        {
            sz_button(2);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            sz_button(3);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            sz_button(4);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            sz_button(5);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            sz_button(6);
        }

        private void button21_Click(object sender, EventArgs e)
        {
            sz_button(7);
        }

        private void button22_Click(object sender, EventArgs e)
        {
            sz_button(8);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            sz_button(9);
        }

        private void button16_Click(object sender, EventArgs e)
        {
            sz_button(0);
        }
          private void car()//运算
        { textBox1.Text += "=";
            switch (c)
            {
                case "+": x = x1 + x2; break;
                case "-": x = x1 - x2; break;
                case "*": x = x1 * x2; break;
                case "/": x = x1 / x2; break;
                case "%": x = x1 % x2; break;
            }
            textBox1.Text =x.ToString();
        }
        private void button19_Click(object sender, EventArgs e)
        {
            ysf_button("+");
        }

        private void button14_Click(object sender, EventArgs e)
        {
            ysf_button("-");
        }

        private void button9_Click(object sender, EventArgs e)
        {
            ysf_button("*");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            ysf_button("%");
        }

        private void button17_Click(object sender, EventArgs e)
        {
            x1 = Convert.ToDouble(textBox1.Text);
            if (x1 != 0)

                x1 = -x1;
            textBox1.Text = x1.ToString();

        }

        private void button18_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.IndexOf(".") == -1)
            {
                textBox1.Text += ".";
            }
            else
            {
                textBox1.Text += "";
            }
        }
        private void button15_Click(object sender, EventArgs e)
        {
            x1 = Convert.ToDouble(textBox1.Text);
            x = 1 / x1;
            textBox1.Text = x.ToString();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            ysf_button("%");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            x1 = Convert.ToDouble(textBox1.Text);
            x = Math.Sqrt(x1);
            textBox1.Text = x.ToString();

        }
        
        private void button20_Click(object sender, EventArgs e)
        {
            car();//调用方法
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "0";
            x1 = 0;
            x2 = 0;
            x = 0;
            c = "";
         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
                textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);

            textBox1.Text = "0";

        }
    }
}
搜索更多相关主题的帖子: 计算器 前辈 麻烦 
2008-12-14 14:59
广陵绝唱
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:29
帖 子:3607
专家分:1709
注 册:2008-2-15
收藏
得分:0 
感觉不象C语言?哪位高手能看出来他用什么写的?然后我帮他转移一下。谢谢。
2008-12-14 19:09
wingfeng
Rank: 2
等 级:论坛游民
帖 子:292
专家分:10
注 册:2008-12-12
收藏
得分:0 
怎么把其它的语言问题发到这里来了!(这里是讨论C语言的
2008-12-14 19:16
t442444956
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-11-16
收藏
得分:0 
是 C# 的!扔到C#去吧!!!

七月之殇
2008-12-14 21:12
广陵绝唱
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:29
帖 子:3607
专家分:1709
注 册:2008-2-15
收藏
得分:0 
回复 第4楼 t442444956 的帖子
谢谢。
2008-12-14 22:08
jidipiaoyu
Rank: 1
等 级:新手上路
帖 子:79
专家分:3
注 册:2008-12-5
收藏
得分:0 
如果是C#的话,你的错误也太多了吧,多到惨不忍睹的地步。。我学C#才一个月,就已经开发了好几个软件了。
2008-12-15 11:05
小仙
Rank: 7Rank: 7Rank: 7
来 自:光之谷
等 级:贵宾
威 望:39
帖 子:1812
专家分:1
注 册:2008-8-8
收藏
得分:0 
嗯,我收了,确实是C#语言的。
另外6楼的朋友很牛啊,厉害,呵呵。
软件其实完成了只是一个阶段,重点是在于去维护,让软件得以提升,我觉得从这里入手不管是对技术的提高,还是软件的质量都要比写得量多来得好。


仁者乐膳,智者乐睡。我都爱~
2008-12-16 00:09
快速回复:我是初学者 做了个计算器 可是计算有问题麻烦各位前辈帮下忙 看看错 ...
数据加载中...
 
   



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

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