标题:我的计算器编程试调时出了一些问题,可以帮我看看怎么改么
取消只看楼主
梨小橙
Rank: 2
等 级:论坛游民
帖 子:28
专家分:13
注 册:2013-5-14
结帖率:100%
已结贴  问题点数:60 回复次数:3 
我的计算器编程试调时出了一些问题,可以帮我看看怎么改么
帮我看看,谢谢!

[ 本帖最后由 梨小橙 于 2013-5-31 13:21 编辑 ]
搜索更多相关主题的帖子: 计算器 看看 
2013-05-31 00:21
梨小橙
Rank: 2
等 级:论坛游民
帖 子:28
专家分:13
注 册:2013-5-14
得分:0 
回复 2楼 邓士林
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
         double num1;
         double num2;
         double resutl;//操作数和运行结果
         bool XiaoShu = false;//判断是否是小数
         string op;      //操作数的类型
         public void numClick(int Mynum)
         {
             if (XiaoShu)
             {
                 textBox1.Text = textBox1.Text + Mynum;
             }
             else
             {
                 if (textBox1.Text == "0.")
                 {
                     textBox1.Text = Mynum + ".";
                 }
                 else
                   {
                     textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1) + Mynum + ".";
                    }
             }
         }

         private void Form1_Load(object sender, EventArgs e)
         {
             textBox1.Text = "0";
             textBox1.TextAlign = HorizontalAlignment.Right;//文本框向右对齐
         }

         private void button17_Click(object sender, EventArgs e)
         {
             num2 = Convert.ToDouble(textBox1.Text);
             switch (op)
             {
                 case "Add":
                     resutl = num1 + num2;
                     textBox1.Text = resutl.ToString();//加的情况
                     break;
                 case "Jian":
                     resutl = num1 - num2;
                     textBox1.Text = resutl.ToString();//减的情况
                     break;
                 case "Cheng":
                     resutl = num1 * num2;
                     textBox1.Text = resutl.ToString();//乘的情况
                     break;
                 case "Chu":
                     if (num2 == 0)
                     {
                         textBox1.Text = "被除数为0,无法整除";
                     }
                     else
                     {
                         resutl = num1 / num2;
                         textBox1.Text = resutl.ToString();//除的情况
                     }
                     break;
                 default:
                     resutl = Math.Sqrt(num1);
                     textBox1.Text = resutl.ToString();//开方的情况
                     break;

             }
         }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button16_Click(object sender, EventArgs e)
        {
            XiaoShu = true;
        }

        private void btnC_Click(object sender, EventArgs e)
        {
            num1 = 0;
            num2 = 0;
            textBox1.Text = "0";
            XiaoShu = false;

        }

        private void button12_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            numClick(1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            numClick(2);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            numClick(3);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            numClick(4);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            numClick(5);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            numClick(6);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            numClick(7);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            numClick(8);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            numClick(9);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            numClick(0);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            op = "Cheng";
            num1 = Convert.ToDouble(textBox1.Text);
            textBox1.Text = "*";
            XiaoShu = false;
        }

        private void button11_Click(object sender, EventArgs e)
        {
            op = "Add";
            num1 = Convert.ToDouble(textBox1.Text);
            textBox1.Text = "+";
            XiaoShu = false;
        }

        private void button13_Click(object sender, EventArgs e)
        {
            op = "Jian";
            num1 = Convert.ToDouble(textBox1.Text);
            textBox1.Text = "-";
            XiaoShu = false;
        }

        private void button15_Click(object sender, EventArgs e)
        {
            op = "Chu";
            num1 = Convert.ToDouble(textBox1.Text);
            textBox1.Text = "/";
            XiaoShu = false;
        }

        private void button18_Click(object sender, EventArgs e)
        {
            op = "PF";
            num1 = Convert.ToDouble(textBox1.Text);
            textBox1.Text = "sqrt";
            XiaoShu = false;
        }
    }
}

一念起,万水千山;
一念灭,沧海桑田。
2013-05-31 13:24
梨小橙
Rank: 2
等 级:论坛游民
帖 子:28
专家分:13
注 册:2013-5-14
得分:0 
回复 2楼 邓士林
我明明截图放上去了,奇怪了

一念起,万水千山;
一念灭,沧海桑田。
2013-05-31 13:25
梨小橙
Rank: 2
等 级:论坛游民
帖 子:28
专家分:13
注 册:2013-5-14
得分:0 
回复 5楼 csharpluntan
WindowsFormsApplication1.rar (45.88 KB)

一念起,万水千山;
一念灭,沧海桑田。
2013-06-01 14:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-412643-1-1.html




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

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