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 Radio
{
public partial class Calculator : Form
{
public Calculator()
{
InitializeComponent();
}
private void calculateClick(object sender, EventArgs e)
{
try
{
if ((bool)addition.Checked)
{
addValues();
}
else if ((bool)subtraction.Checked)
{
subtractValues();
}
else if ((bool)multiplication.Checked)
{
multiplyValues();
}
else if ((bool)division.Checked)
{
divideValues();
}
else if ((bool)remainder.Checked)
{
remainderValues();
}
}
catch (Exception caught)
{
expression.Text = "";
result.Text = caught.Message;
}
}
private void addValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome = 0;
// TODO: Add rhs to lhs and store the result in outcome
outcome = lhs + rhs;
expression.Text = lhsOperand.Text + " + " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void subtractValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome = 0;
// TODO: Subtract rhs from lhs and store the result in outcome
outcome = lhs - rhs;
expression.Text = lhsOperand.Text + " - " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void multiplyValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome = 0;
// TODO: Multiply lhs by rhs and store the result in outcome
outcome = lhs * rhs;
expression.Text = lhsOperand.Text + " * " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void divideValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome = 0;
// TODO: Divide lhs by rhs and store the result in outcome
outcome = lhs / rhs;
expression.Text = lhsOperand.Text + " / " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void remainderValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome = 0;
// TODO: Work out the remainder after dividing lhs by rhs and store the result in outcome
outcome = lhs % rhs;
expression.Text = lhsOperand.Text + " % " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void IsChecked(object sender, EventArgs e)
{
}
}
}
C# Radio Button Calculator source code
Post A Comment:
0 comments: