用C#编写计算器
零有点问题,而且目前只能做一些简单的运算,+、-、*、/、平方、开根号
希望有大佬指正我的错误
感谢
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#编写计算器的更多相关文章
- 纯javascript代码编写计算器程序
今天来分享一下用纯javascript代码编写的一个计算器程序,很多行业都能用到这个程序,例如做装修预算.贷款利率等等. 首先来看一下完成后的效果: 具体代码如下:(关注我的博客,及时获取最新WEB前 ...
- JavaScript编写计算器的发展史
JavaScript编写计算器的发展史: 编写一个普通的四则运算: <!DOCTYPE html> <html lang="en"> <head> ...
- Java语言编写计算器(简单的计算器)
Java编写的一个简单计算器,本人还比较菜,只能这样了,有点代码冗余,不能连续计算. import javax.swing.*; import java.awt.*; import java.awt. ...
- 第二次作业利用java语言编写计算器进行四则运算
随着第一次作业的完成,助教 牛老师又布置了第二次作业:用java语言编写一个程序然后进行四则运算用户用键盘输入一个字符来结束程序显示统计结果.一开始看到这个题目我也着实吓了一跳 因为不知道如何下手而且 ...
- C++Builder编写计算器
用C++Builder确实能快速上手, 只要是会一点C++基础的,都能很快的编写一些小程序,而且VCL库组件也很丰富,比微软MFC强多了. 自己动手写了一个计算器来增加自己的兴趣.C++基础以后有空还 ...
- c# 委托delegate 编写计算器
.Net 中的委托类似于 C 或 C++ 中的函数指针.使用委托使程序员可以将方法引用封装在委托对象内.然后可以将该委托对象传递给可调用所引用方法的代码,而不必在编译时知道将调用哪个方法.与 C 或 ...
- 利用MFC编写计算器
端午节这两天没什么事,就用MFC写了一个简单的计算器,界面做的也比较简单,如下图1,可以进行简单的加.减.乘和除功能,小数点显示这块做的不是很好,比如输入1.2,不会一个个的显示,而是先显示“1”,后 ...
- 利用Python代码编写计算器小程序
import tkinter import tkinter.messagebox import math class JSQ: def __init__(self): #创建主界面 self.root ...
- 编写计算器程序学习JS责任链模式
设计模式中的责任链模式能够很好的处理程序过程的逻辑判断,提高程序可读性. 责任链模式的核心在于责任链上的元素判断能够处理该数据,不能处理的话直接交给它的后继者. 计算器的基本样式: 通过div+css ...
- JavaScript 如何编写计算器
1.JavaScript制作计算器 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
随机推荐
- spring+mybatis多数据源,动态切换
有时我们项目中需要配置多个数据源,不同的业务使用的数据库不同 实现思路:配置多个dataSource ,再配置多个sqlSessionFactory,和dataSource一一对应.重写SqlSess ...
- 九度OJ 1091:棋盘游戏 (DP、BFS、DFS、剪枝)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1497 解决:406 题目描述: 有一个6*6的棋盘,每个棋盘上都有一个数值,现在又一个起始位置和终止位置,请找出一个从起始位置到终止位置代 ...
- IP address could not be resolved: Name or service not known
[root@test ~]# /usr/local/mysql/bin/mysqld2018-08-05T07:00:33.647509Z 0 [Warning] [MY-011070] [Serve ...
- Android在有存储卡和无存储卡情况下拍照后固定尺寸和压缩大小
我最近工作挺忙,距离上一次写博客转眼已经过了一个多月,每次学到和用到点新东西,其实都有分享的欲望,但奈何文笔太差,而一篇文章包括构思,排版,修改发布的时间最少要花费2个小时(这其中还不包括写完后未保存 ...
- HDU2068 RPG的错排 —— 错排
题目链接:https://vjudge.net/problem/HDU-2068 RPG的错排 Time Limit: 1000/1000 MS (Java/Others) Memory Lim ...
- C#评分小系统练习
一个经理类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...
- Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���ʱ��’ is unrecognized or represents more than one time zone.
Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���ʱ��’ is unrecogn ...
- 普通用户Mysql 5.6.13 主从,主主及nagios的mysql slave监控
Master:192.168.209.19 Slave:192.168.209.20 mysql版本:mysql5.6.13 1. 以root身份创建普通用户,如mysql,并创建mysql安装目录: ...
- CV_Assert
转:http://blog.csdn.net/ding977921830/article/details/46376847 Checks a condition at runtime and thro ...
- intellj idea 使用
1. 导入包快捷 Alt + Enter 2. 查看方法注释,点击进入源码即可,若想和eclipse一样鼠标停留即可出现注释提示,开启方法为: Preferences->Editor->G ...