用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" ...
随机推荐
- sort_action
li, r = [23,8, 45, 5, 0, -6, 745,8, 8], [] while (len(li) > 0): loop_, min, tag = len(li), li[0], ...
- ABAP 日期栏函数
在SZC这个中有很多日期函数可以研究借鉴 ABAP - 日期格式转换 现在提供以下一些日期格式转换的函数: Below are several FMs which can be used to c ...
- Redis C语言操作封装
#ifndef BOYAA_FOURLANDLORD_REDISCLASS_H_20130217 #define BOYAA_FOURLANDLORD_REDISCLASS_H_20130217 #i ...
- The import ....cannot be resolved 解决方法
1:右击项目build path>configure build path>libraries看有没感叹号什么的不正常的lib,移除掉 2:点击项目的build path>confi ...
- Oracle数据查看被锁住的用户
//lock_date是被锁住时间,如果为空证明这个用户没有被锁住 select username,lock_date from dba_users where username='GFMIS'; ...
- html页面表格导出到excel总结
转载:http://www.cnblogs.com/liuguanghai/archive/2012/12/31/2840262.html <table id="tableExcel& ...
- RightScale发布2017年度云调查报告
RightScale最近发布了他们的年度云报告(RightScale 2017云现状报告,RightScale 2017 State of the Cloud Report),这份报告包括了云计算在采 ...
- Struts2 拦截器配置及使用
在我的项目中有个需求,实现记录用户操作的系统日志,基于这个功能我首先想到的是Struts 的拦截器.配置一个全部Action都会拦截的拦截,写一个公用的服务.每当用户发送请求到Action 就记录相应 ...
- WPF Combo box 获取选择的Tag
string str1 = ((ComboBoxItem)this.cboBoxRate1553B.Items[this.cboBoxRate1553B.SelectedIndex]).Tag.ToS ...
- BZOJ_2438_[中山市选2011]杀人游戏 _强连通分量
BZOJ_2438_[中山市选2011]杀人游戏 _强连通分量 Description 一位冷血的杀手潜入 Na-wiat,并假装成平民.警察希望能在 N 个人里面,查出谁是杀手.警察能够对每一个人 ...