Question: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;

namespace Calculator { ///

/// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public enum Operator {None, Plus, Minus, Times, Divide, Equals} private Operator lastOperator = Operator.None; private decimal valueSoFar = 0; private bool numberHitSinceLastOperator = false; private decimal memory; decimal EndResult = 0; decimal MemoryStore = 0; public MainWindow() { InitializeComponent(); }

private void sub_Click(object sender, RoutedEventArgs e) { }

private void button1_Click(object sender, RoutedEventArgs e) { HandleDigit(1); }

private void button2_Click(object sender, RoutedEventArgs e) { HandleDigit(2); }

private void button3_Click(object sender, RoutedEventArgs e) { HandleDigit(3); }

private void button4_Click(object sender, RoutedEventArgs e) { HandleDigit(4); }

private void button5_Click(object sender, RoutedEventArgs e) { HandleDigit(5); }

private void button6_Click(object sender, RoutedEventArgs e) { HandleDigit(6); }

private void button7_Click(object sender, RoutedEventArgs e) { HandleDigit(7); }

private void button8_Click(object sender, RoutedEventArgs e) { HandleDigit(8); }

private void button9_Click(object sender, RoutedEventArgs e) { HandleDigit(9); }

private void button0_Click(object sender, RoutedEventArgs e) { HandleDigit(0); }

private void HandleDigit(int digit) { string valueSoFar = numberHitSinceLastOperator ? textboxDisplay.Text : ""; string newValue = valueSoFar + digit.ToString(); textboxDisplay.Text = newValue; numberHitSinceLastOperator = true; }

private void OnClickOperator(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn.Tag != null) { Operator op = (Operator)btn.Tag; ExecuteLastOperator(op); } }

private void Window_Loaded_1(object sender, RoutedEventArgs e) { buttonMul.Tag = Operator.Times; buttonDiv.Tag = Operator.Divide; buttonSub.Tag = Operator.Minus; buttonAdd.Tag = Operator.Plus; buttonEqu.Tag = Operator.Equals; }

private void ExecuteLastOperator(Operator newOperator) { decimal currentValue = Convert.ToDecimal(textboxDisplay.Text); decimal newValue = currentValue; if (numberHitSinceLastOperator) { switch (lastOperator) { case Operator.Plus: newValue = valueSoFar + currentValue; break; case Operator.Minus: newValue = valueSoFar - currentValue; break; case Operator.Times: newValue = valueSoFar * currentValue; break; case Operator.Divide: if (currentValue == 0) newValue = 0; else newValue = valueSoFar / currentValue; break; case Operator.Equals: newValue = currentValue; break;

} }

valueSoFar = newValue; lastOperator = newOperator; numberHitSinceLastOperator = false; textboxDisplay.Text = valueSoFar.ToString();

}

private void clr_Click(object sender, RoutedEventArgs e) { textboxDisplay.Text = ""; } private void CE_Click(object sender, RoutedEventArgs e) { textboxDisplay.Clear(); } private void memoryrecall_Click(object sender, RoutedEventArgs e) { textboxDisplay.Text = memory.ToString(); }

private void memoryclr_Click(object sender, RoutedEventArgs e) { textboxDisplay.Text = "0"; memory = 0; } private void memorystore_Click(object sender, RoutedEventArgs e) { memory += Decimal.Parse(textboxDisplay.Text); textboxDisplay.Clear(); }

private void madd_Click(object sender, RoutedEventArgs e) { MemoryStore += EndResult; textboxDisplay.Text = MemoryStore.ToString(); }

private void msub_Click(object sender, RoutedEventArgs e) { MemoryStore -= EndResult; textboxDisplay.Text = MemoryStore.ToString(); }

}

}

When I will store value and recall value, it's will work but memory recall value cannot perform arthematic operation.

for example:

press digit 5 and click Memory store

6*memory recall i.e. 5 = 30 (Desired output)

But,

it doesn't work that way.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!