为什么我做的计算器只能算乘法和除法,求大神帮看看
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//获取输入的数值
//试一试这么做行不行
int Num1;
int Num2;
int Num3;
try
{
Num1 = int.Parse(textBox_Num1.Text);
Num2 = int.Parse(textBox_Num2.Text);
if (radioButton1.Checked)//判断运算规则,加法
{
Num3 = Num1 + Num2;//计算结果
}
else if (radioButton2.Checked)//减法
{
Num3 = Num1 - Num2;//计算结果
}
if (radioButton3.Checked)//判断运算规则,加法
{
Num3 = Num1 * Num2;//计算结果
}
else
{
Num3 = Num1 / Num2;//计算结果
}
textBox_Num3.Text = Num3.ToString();
}
catch //运行出错,则进去catch
{
MessageBox.Show("输入数据类型有误,请重新输入");
}
}
}
}