panking还没秃 2018-12-28 18:51 采纳率: 0%
浏览 566

编写计算器时为什么显示输入字符串的格式不正确?

用的mfc2010窗体编写的简易计算器

加减乘除都没问题,做到了平方和开方时总是报错运行不了...从加法开始的代码如下: private void button11_Click(object sender, EventArgs e)
{
ysfs = 1;
temp1 = Convert.ToDouble(textBox1.Text);
textBox2.Text = "+";
textBox1.Text = " ";
} //+

    private void button12_Click(object sender, EventArgs e)
    {
        ysfs = 2;
        temp1 = Convert.ToDouble(textBox1.Text);
        textBox2.Text = "-";
        textBox1.Text = " ";
    }
    //-
    private void button13_Click(object sender, EventArgs e)
    {
        ysfs = 3;
        temp1 = Convert.ToDouble(textBox1.Text);
        textBox2.Text = "*";
        textBox1.Text = " ";
    } //*

    private void button14_Click(object sender, EventArgs e)
    {
        ysfs = 4;
        temp1 = Convert.ToDouble(textBox1.Text);
        textBox2.Text = "/";
        textBox1.Text = " ";
    } ///
    private void button17_Click(object sender, EventArgs e)
    {
        ysfs = 5;
        temp1 = Convert.ToDouble(textBox1.Text);
        textBox2.Text = "²";
        textBox1.Text = " ";
    } //平方
    private void button20_Click(object sender, EventArgs e)
    {
        double temp2 = Convert.ToDouble(textBox1.Text);
        switch (ysfs)
        {
            case 1:
                textBox1.Text = (temp1 + temp2).ToString();
                break;
            case 2:
                textBox1.Text = (temp1 - temp2).ToString();
                break;
            case 3:
                textBox1.Text = (temp1 * temp2).ToString();
                break;
            case 4:
                textBox1.Text = (temp1 / temp2).ToString();
                break;
            case 5:
                textBox1.Text = (Math.Pow(temp1, 2)).ToString();
                break;
            case 6:
                textBox1.Text = Math.Sqrt(temp1).ToString();
                break;
        }
    }//等于![图片说明](https://img-ask.csdn.net/upload/201812/28/1545994424_745007.png)
  • 写回答

1条回答

  • threenewbee 2018-12-28 11:41
    关注

    mfc2010个鬼,这是C#的程序。输入字符串的格式不正确,说明文本框里的内容不是合法的数字不能转换为double

    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿