c 加减乘除建议计算机,如何制作简单的计算器(加减乘除)

本文介绍了一个简易计算器的实现方式,通过C#编程语言创建了一个Windows Forms应用程序。该计算器能够进行基本的算术运算,如加法、减法、乘法和除法,并通过按钮点击输入数字,最终结果显示在文本框中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

缘分啊!

我正在在做这个!

我把自己做的一个代码贴出来给你看吧

using System;

using System.Collections.Generic;

using

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace CalcDemo

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

int i = 0;

double x = 0.0;

double y = 0.0;

int z = 0;

int j = 0;

private void IncreaseI()

{

if (i%2 == 0)

{

x = z;

}

else if ( i%2 == 1 )

{

y = z;

}

i++;

if (i > 1)

{

i = 0;

}

textBox1.Text = z.ToString();

}

private void button10_Click(object sender, EventArgs e)

{

z = 0;

IncreaseI();

}

private void button5_Click(object sender, EventArgs e)

{

z = 1;

IncreaseI();

}

private void button7_Click(object sender, EventArgs e)

{

z = 2;

IncreaseI();

}

private void button9_Click(object sender, EventArgs e)

{

z = 3;

IncreaseI();

}

private void button4_Click(object sender, EventArgs e)

{

z = 4;

IncreaseI();

}

private void button6_Click(object sender, EventArgs e)

{

z = 5;

IncreaseI();

}

private void button8_Click(object sender, EventArgs e)

{

z = 6;

IncreaseI();

}

private void button1_Click(object sender, EventArgs e)

{

z = 7;

IncreaseI();

}

private void button2_Click(object sender, EventArgs e)

{

z = 8;

IncreaseI();

}

private void button3_Click(object sender, EventArgs e)

{

z = 9;

IncreaseI();

}

private void button12_Click(object sender, EventArgs e)

{

j = 1;

}

private void button13_Click(object sender, EventArgs e)

{

j = 2;

}

private void button14_Click(object sender, EventArgs e)

{

j = 3;

}

private void button15_Click(object sender, EventArgs e)

{

j = 4;

}

private void button11_Click(object sender, EventArgs e)

{

switch (j)

{

case 1:

textBox1.Text = Convert.ToString(x + y);

break;

case 2:

textBox1.Text = Convert.ToString(x - y);

break;

case 3:

textBox1.Text = Convert.ToString(x * y);

break;

case 4:

textBox1.Text = Convert.ToString(x / y);

break;

default:

break;

}

}

private void Form1_Load(object sender, EventArgs e)

{

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值