namespace FractionCalculatorWithGUI_Final { public partial class MainForm : Form { private enum DISPLAY_MODE { CURRRENT_VALUE, ACCUMULATOR, ERROR} private enum OPERATION {ADD, SUB, MUL, DIV} private int accumulator = 0; private OPERATION currentOperation = OPERATION.ADD; private int currentValue = 0; private DISPLAY_MODE displayMode = DISPLAY_MODE.CURRRENT_VALUE; public MainForm() { InitializeComponent(); } //Text Box private void textBoxDisplay_TextChanged(object sender, EventArgs e) { } private void UpdateDisplay() { switch (displayMode) { case DISPLAY_MODE.ACCUMULATOR: textBoxDisplay.Text = accumulator.ToString(); break; case DISPLAY_MODE.CURRRENT_VALUE: textBoxDisplay.Text = currentValue.ToString(); break; case DISPLAY_MODE.ERROR: textBoxDisplay.Text = "Error"; break; } } //Slash Button private void buttonSlash_Click(object sender, EventArgs e) { displayMode = DISPLAY_MODE.CURRRENT_VALUE; currentValue = 0; textBoxDisplay.Text = "/"; } //numeric buttons private void NumberKeyHit(int number) { displayMode = DISPLAY_MODE.CURRRENT_VALUE; currentValue = currentValue * 10 + number; UpdateDisplay(); } private void button0_Click(object sender, EventArgs e) { NumberKeyHit(0); } private void button1_Click(object sender, EventArgs e) { NumberKeyHit(1); } private void button2_Click(object sender, EventArgs e) { NumberKeyHit(2); } private void button3_Click(object sender, EventArgs e) { NumberKeyHit(3); } private void button4_Click(object sender, EventArgs e) { NumberKeyHit(4); } private void button5_Click(object sender, EventArgs e) { NumberKeyHit(5); } private void button6_Click(object sender, EventArgs e) { NumberKeyHit(6); } private void button7_Click(object sender, EventArgs e) { NumberKeyHit(7); } private void button8_Click(object sender, EventArgs e) { NumberKeyHit(8); } private void button9_Click(object sender, EventArgs e) { NumberKeyHit(9); } private void MainForm_Load(object sender, EventArgs e) { UpdateDisplay(); } private void OperationKeyHit(OPERATION op) { PerformOperation(); currentOperation= op; currentValue = 0; UpdateDisplay(); } //mathematical operations private void PerformOperation() { switch (currentOperation) { case OPERATION.ADD: accumulator += currentValue; break; case OPERATION.SUB: accumulator -= currentValue; break; case OPERATION.MUL: accumulator *= currentValue; break; case OPERATION.DIV: accumulator /= currentValue; break; } currentValue = 0; displayMode = DISPLAY_MODE.ACCUMULATOR; UpdateDisplay(); } //Operational Buttons private void buttonPlus_Click(object sender, EventArgs e) { OperationKeyHit(OPERATION.ADD); } private void buttonEquals_Click(object sender, EventArgs e) { PerformOperation(); } private void buttonMinus_Click(object sender, EventArgs e) { OperationKeyHit(OPERATION.SUB); } private void buttonDivide_Click(object sender, EventArgs e) { OperationKeyHit(OPERATION.DIV); } private void buttonTimes_Click(object sender, EventArgs e) { OperationKeyHit(OPERATION.MUL); } private void buttonClear_Click(object sender, EventArgs e) { currentValue = 0; displayMode = DISPLAY_MODE.CURRRENT_VALUE; UpdateDisplay(); } private void buttonAllClear_Click(object sender, EventArgs e) { currentValue = 0; accumulator= 0; displayMode = DISPLAY_MODE.CURRRENT_VALUE; currentOperation = OPERATION.ADD; UpdateDisplay(); } } }