零有点问题,而且目前只能做一些简单的运算,+、-、*、/、平方、开根号

希望有大佬指正我的错误

感谢

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
double a;//第一个运算数
double b;//第二个运算数
string d;//结果
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += "1";
}

private void button2_Click(object sender, EventArgs e)
{
textBox1.Text += "2";
}

private void button3_Click(object sender, EventArgs e)
{
textBox1.Text += "3";
}

private void button4_Click(object sender, EventArgs e)
{
textBox1.Text += "4";
}

private void button5_Click(object sender, EventArgs e)
{
textBox1.Text += "5";
}

private void button6_Click(object sender, EventArgs e)
{
textBox1.Text += "6";
}

private void button7_Click(object sender, EventArgs e)
{
textBox1.Text += "7";
}

private void button8_Click(object sender, EventArgs e)
{
textBox1.Text += "8";
}

private void button9_Click(object sender, EventArgs e)
{
textBox1.Text += "9";
}

private void button16_Click(object sender, EventArgs e)
{
textBox1.Text += "0";
if (d == "/")
{
MessageBox.Show("除数不能为零", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

private void button14_Click(object sender, EventArgs e)
{
b = double.Parse(textBox1.Text);//parse 解析,把字符串转化为整型,转换数据类型
textBox1.Text = "";
d = "+";
}

private void button15_Click(object sender, EventArgs e)
{
b = double.Parse(textBox1.Text);
textBox1.Text = "";
d = "-";
}

private void button12_Click(object sender, EventArgs e)
{
b = double.Parse(textBox1.Text);
textBox1.Text = "";
d = "*";
}

private void button13_Click(object sender, EventArgs e)
{
b = double.Parse(textBox1.Text);
textBox1.Text = "";
d = "/";
}

private void button10_Click(object sender, EventArgs e)
{
b = double.Parse(textBox1.Text);
textBox1.Text = "";
d = "pow";
}

private void button11_Click(object sender, EventArgs e)
{
b = double.Parse(textBox1.Text);
textBox1.Text = "";
d = "sqrt";
}

private void button18_Click(object sender, EventArgs e)
{
switch (d)
{
case "+": a=b+ double.Parse(textBox1.Text);
break;
case "-": a = b - double.Parse(textBox1.Text);
break;
case "*": a = b * double.Parse(textBox1.Text);
break;
case "/": a = b / double.Parse(textBox1.Text);
break;
case "pow": a = Math.Pow(b,2.0);
break;
case "sqrt": a = Math.Sqrt(b);
break;
}
textBox1.Text = a + "";
}

private void button19_Click(object sender, EventArgs e)
{
textBox1.Text = "";
}

private void button17_Click(object sender, EventArgs e)//小数点
{
if (textBox1.Text != "")
{
textBox1.Text += ".";
}
}
}
}

用C#编写计算器的更多相关文章

  1. 纯javascript代码编写计算器程序

    今天来分享一下用纯javascript代码编写的一个计算器程序,很多行业都能用到这个程序,例如做装修预算.贷款利率等等. 首先来看一下完成后的效果: 具体代码如下:(关注我的博客,及时获取最新WEB前 ...

  2. JavaScript编写计算器的发展史

    JavaScript编写计算器的发展史: 编写一个普通的四则运算: <!DOCTYPE html> <html lang="en"> <head> ...

  3. Java语言编写计算器(简单的计算器)

    Java编写的一个简单计算器,本人还比较菜,只能这样了,有点代码冗余,不能连续计算. import javax.swing.*; import java.awt.*; import java.awt. ...

  4. 第二次作业利用java语言编写计算器进行四则运算

    随着第一次作业的完成,助教 牛老师又布置了第二次作业:用java语言编写一个程序然后进行四则运算用户用键盘输入一个字符来结束程序显示统计结果.一开始看到这个题目我也着实吓了一跳 因为不知道如何下手而且 ...

  5. C++Builder编写计算器

    用C++Builder确实能快速上手, 只要是会一点C++基础的,都能很快的编写一些小程序,而且VCL库组件也很丰富,比微软MFC强多了. 自己动手写了一个计算器来增加自己的兴趣.C++基础以后有空还 ...

  6. c# 委托delegate 编写计算器

    .Net 中的委托类似于 C 或 C++ 中的函数指针.使用委托使程序员可以将方法引用封装在委托对象内.然后可以将该委托对象传递给可调用所引用方法的代码,而不必在编译时知道将调用哪个方法.与 C 或 ...

  7. 利用MFC编写计算器

    端午节这两天没什么事,就用MFC写了一个简单的计算器,界面做的也比较简单,如下图1,可以进行简单的加.减.乘和除功能,小数点显示这块做的不是很好,比如输入1.2,不会一个个的显示,而是先显示“1”,后 ...

  8. 利用Python代码编写计算器小程序

    import tkinter import tkinter.messagebox import math class JSQ: def __init__(self): #创建主界面 self.root ...

  9. 编写计算器程序学习JS责任链模式

    设计模式中的责任链模式能够很好的处理程序过程的逻辑判断,提高程序可读性. 责任链模式的核心在于责任链上的元素判断能够处理该数据,不能处理的话直接交给它的后继者. 计算器的基本样式: 通过div+css ...

  10. JavaScript 如何编写计算器

    1.JavaScript制作计算器 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

随机推荐

  1. 发送get和post请求时常用的content-type

    常见的媒体格式类型如下: text/html : HTML格式 text/plain :纯文本格式 text/xml :  XML格式 image/gif :gif图片格式 image/jpeg :j ...

  2. sort_action

    li, r = [23,8, 45, 5, 0, -6, 745,8, 8], [] while (len(li) > 0): loop_, min, tag = len(li), li[0], ...

  3. 关于4Ps 、4Cs 、4Rs 、4Vs营销策略的内容及优劣比较

  4. 怎样把word直接转换成ppt

  5. [2017-09-05]Abp系列——Abp后台作业系统介绍与经验分享

    本系列目录:Abp介绍和经验分享-目录 什么是后台作业系统 后台作业系统即BackgroundJob,从需求上讲,是一套基础设施,允许我们定义一个作业,在未来指定的某个时间去执行. 后台作业的一般场景 ...

  6. Xcode工程断点调试失效

    1.我解决的是方法是,选择Product---->Edit Scheme------>(这里进入后会有Info,Arguments,Options,Diagnostics)选择Info-- ...

  7. linux EXT文件系统

    将一个硬盘分区之后如何创建文件系统(windows来讲就是如何针对分区来进行格式化,是采用FAT32的文件系统来格式化,还是采用NTFS的文件系统来格式化).Linux主要采用EXT2,EXT3分区格 ...

  8. hdu1052 田忌赛马 —— 贪心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 错误代码: #include<stdio.h>//田忌赛马,错误版 #include ...

  9. HDU6025 Coprime Sequence —— 前缀和 & 后缀和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6025 Coprime Sequence Time Limit: 2000/1000 MS (Java/ ...

  10. Good Bye 2015 B. New Year and Old Property —— dfs 数学

    题目链接:http://codeforces.com/problemset/problem/611/B B. New Year and Old Property time limit per test ...