Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using CalculatorPrivateAssembly;
- namespace BasicCalculator1
- {
- public partial class frmBasicCalculator : Form
- {
- public frmBasicCalculator()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (cbOperator.SelectedItem == null)
- {
- rtbResult.Text = "Error:\n" + "Please select an Operator.";
- }
- float a = 0, b = 0;
- parseCheck(tbNum1, out a, "First");
- parseCheck(tbNum2, out b, "Second");
- if (a != 0 && b != 0 && cbOperator != null)
- {
- switch (cbOperator.SelectedItem)
- {
- case "x":
- printResult(BasicCalculator.Multiplication(a, b));
- break;
- case "/":
- printResult(BasicCalculator.Division(a, b));
- break;
- case "+":
- printResult(BasicCalculator.Addition(a, b));
- break;
- case "-":
- printResult(BasicCalculator.Subtraction(a, b));
- break;
- }
- }
- }
- void parseCheck(TextBox a, out float b, string c)
- {
- if (!float.TryParse(a.Text, out b))
- {
- rtbResult.Text = "Error:\n" + c + " entry is invalid";
- }
- }
- void printResult(float a)
- {
- rtbResult.Text = "Result:\n" + a.ToString();
- }
- }
- }
Add Comment
Please, Sign In to add comment