Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Calculator
- {
- public partial class CalculatorForm : Form
- {
- int firstNum = 0;
- int result = 0;
- bool addButtonFlag = false;
- bool subtractButtonFlag = false;
- bool multiplyButtonFlag = false;
- bool divideButtonFlag = false;
- public CalculatorForm()
- {
- InitializeComponent();
- }
- private void One_Click(object sender, EventArgs e)
- {
- InputBox.Text += "1";
- }
- private void Two_Click(object sender, EventArgs e)
- {
- InputBox.Text += "2";
- }
- private void Three_Click(object sender, EventArgs e)
- {
- InputBox.Text += "3";
- }
- private void Four_Click(object sender, EventArgs e)
- {
- InputBox.Text += "4";
- }
- private void Five_Click(object sender, EventArgs e)
- {
- InputBox.Text += "5";
- }
- private void Six_Click(object sender, EventArgs e)
- {
- InputBox.Text += "6";
- }
- private void Seven_Click(object sender, EventArgs e)
- {
- InputBox.Text += "7";
- }
- private void Eight_Click(object sender, EventArgs e)
- {
- InputBox.Text += "8";
- }
- private void Nine_Click(object sender, EventArgs e)
- {
- InputBox.Text += "9";
- }
- private void Zero_Click(object sender, EventArgs e)
- {
- InputBox.Text += "0";
- }
- private void ClearEverything_Click(object sender, EventArgs e)
- {
- result = 0;
- firstNum = 0;
- InputBox.Text = "";
- addButtonFlag = false;
- subtractButtonFlag = false;
- }
- private void Plus_Click(object sender, EventArgs e)
- {
- if (InputBox.Text != "")
- {
- firstNum = int.Parse(InputBox.Text);
- InputBox.Text = "";
- addButtonFlag = true;
- }
- else
- {
- MessageBox.Show("You must enter a number!");
- }
- }
- private void Minus_Click(object sender, EventArgs e)
- {
- if (InputBox.Text != "")
- {
- firstNum = int.Parse(InputBox.Text);
- InputBox.Text = "";
- subtractButtonFlag = true;
- }
- else
- {
- MessageBox.Show("You must enter a number!");
- }
- }
- private void Multiply_Click(object sender, EventArgs e)
- {
- if (InputBox.Text != "")
- {
- firstNum = int.Parse(InputBox.Text);
- InputBox.Text = "";
- multiplyButtonFlag = true;
- }
- else
- {
- MessageBox.Show("You must enter a number!");
- }
- }
- private void Divide_Click(object sender, EventArgs e)
- {
- if (InputBox.Text != "")
- {
- firstNum = int.Parse(InputBox.Text);
- InputBox.Text = "";
- divideButtonFlag = true;
- }
- else
- {
- MessageBox.Show("You must enter a number!");
- }
- }
- private void Equals_Click(object sender, EventArgs e)
- {
- int secondNum = int.Parse(InputBox.Text);
- {
- if (InputBox.Text != "")
- {
- if (addButtonFlag == true)
- result = firstNum + secondNum;
- else if (subtractButtonFlag == true)
- result = firstNum - secondNum;
- else if (divideButtonFlag == true)
- try
- {
- result = firstNum / secondNum;
- }
- catch (System.Exception ex)
- {
- String error = ex.Message;
- MessageBox.Show(error, "Oops! Please try again!");
- }
- else if (multiplyButtonFlag == true)
- result = firstNum * secondNum;
- InputBox.Text = result.ToString();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement