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



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

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