// Button / private void BtnDivision_Click(object sender, RoutedEventArgs e) { if (TbInputNumbers.Text != "0") { //Progress of the calculation's text TbCalculationProgress.Text += TbInputNumbers.Text; if (NewCalculation == true) { //Converting the Current number which is inside the TbInputNumbers TextBlock //Adding the Current number to the Memory array, incrementing the Memory array's index counter by one CurrentNumber = Convert.ToDouble(TbInputNumbers.Text); Calculations.AddToMemory(CurrentNumber); Calculations.IncrementMemoryIndexByOne(); UserCanDeleteLastNumber = true; } //if this is inside the program, then the multiple calculation part does not work //Replacing the CurrentNumber part works more effectively and it is easire to understand //Calculations.IncrementMemoryIndexByOne(); //Checking if there is a new calculation in progress or not //Converting the Current number which is inside the TbInputNumbers TextBlock //Adding the Current number to the Memory array, incrementing the Memory array's index counter by one //Storing the calculation in the result variable (Rounding the result) //Showing the user the given result in the TbResultmemory textBlock //Adding the result to the Memory array, incrementing the Memory array's index counter by one if (NewCalculation == false) { CurrentNumber = Convert.ToDouble(TbInputNumbers.Text); Calculations.AddToMemory(CurrentNumber); Result = Calculations.Division(); Math.Round(Result, 10); TbResultMemory.Text = Result.ToString(); Calculations.AddToMemory(Result); Calculations.IncrementMemoryIndexByOne(); NewCalculation = true; UserCanDeleteLastNumber = false; } } else if (TbInputNumbers.Text == "0") { double MostRecentlyAddedResult = Calculations.GiveBackMostRecentValueOfResultMemory(); //Checking whether the memory has been cleared or not //Progress of the calculation's text if (MemoryHasBeenCleared == true) { TbCalculationProgress.Text += MostRecentlyAddedResult.ToString(); MemoryHasBeenCleared = false; } //Increment the index by one as we are not calculating but waiting for a new input //(if this is not here then the result STEP of the Memory array will always change to the new input) Calculations.IncrementMemoryIndexByOne(); } //We add the button's text to the TbCalculationProgress textblock TbCalculationProgress.Text += "/"; //After the calculation this variable will always be one CalculationIsOnGoing = 1; //Setting the TbInputNumbers Textblock's text to default after every calculation TbInputNumbers.Text = "0"; }
//button √ private void BtnSquareRoot_Click(object sender, RoutedEventArgs e) { if (NoCalculationsYet == true) { //Converting the Current number which is inside the TbInputNumbers TextBlock //Adding the Current number to the Memory array,Incrementing the MemoryIndex by one //Storing the calculation in the result variable (Rounding the result) //Showing the user the given result in the TbResultmemory textBlock //We add the button's text to the TbCalculationProgress textblock //Adding the result to the Memory array and ResultMemory array //incrementing the Memory array's and ResultMemory array's index counter by one //Incrementing the navigator by one and setting the navigator on this side to the new value double CurrentNumber = Convert.ToDouble(TbInputNumbers.Text); Calculations.AddToMemory(CurrentNumber); Calculations.IncrementMemoryIndexByOne(); double Result = Calculations.SquareRootNumber(); Math.Round(Result, 10); TbResultMemory.Text = Result.ToString(); TbCalculationProgress.Text = "√" + CurrentNumber + ""; Calculations.AddToMemory(Result); Calculations.AddToResultMemory(Result); Calculations.IncrementResultMemoryIndexByOne(); Calculations.IncrementResultMemoryNavigatorByOne(); //Setting the NoCalculationsYet variable to false as we've just calculated the result NoCalculationsYet = false; } else if (NoCalculationsYet == false) { //Storing the previous element of the Memory array in the Previous number variable //Storing the calculation in the result variable (Rounding the result) //Showing the user the given result in the TbResultmemory textBlock //We add the button's text to the TbCalculationProgress textblock //Adding the result to the Memory array and ResultMemory array //incrementing the Memory array's and ResultMemory array's index counter by one //Incrementing the navigator by one and setting the navigator on this side to the new value Calculations.IncrementMemoryIndexByOne(); double PreviousNumber = Calculations.GiveBackPreviousElementOfMemory(); double Result = Calculations.SquareRootNumber(); Math.Round(Result, 10); TbResultMemory.Text = Result.ToString(); TbCalculationProgress.Text = "(" + PreviousNumber + " * " + PreviousNumber + ")"; Calculations.AddToMemory(Result); Calculations.AddToResultMemory(Result); Calculations.IncrementResultMemoryIndexByOne(); Calculations.IncrementResultMemoryNavigatorByOne(); } //Setting the UserCanDeleteLastNumber variable to false as the user cannot Delete back from the result UserCanDeleteLastNumber = false; //Setting this variable to false as the user can use division or multiplication, because the Memory array is not empty NewCalculation = false; //After the calculation this variable will always be one CalculationIsOnGoing = 1; //Setting the TbInputNumbers Textblock's text to default after every calculation TbInputNumbers.Text = "0"; }
//Button = private void BtnSummarize_Click(object sender, RoutedEventArgs e) { //We add the button's text to the TbCalculationProgress textblock TbCalculationProgress.Text += "="; //The most recently used operator is required for the right calculation method string CalculationProgress = TbCalculationProgress.Text; for (int i = 0; i < CalculationProgress.Length; i++) { if (CalculationProgress[i].ToString() == "+") { LastOperatorUsedByUser = "******"; } else if (CalculationProgress[i].ToString() == "-") { LastOperatorUsedByUser = "******"; } else if (CalculationProgress[i].ToString() == "/") { LastOperatorUsedByUser = "******"; } else if (CalculationProgress[i].ToString() == "*") { LastOperatorUsedByUser = "******"; } } //Storing the current number which is inside the tbINputNumbers textblock,Adding current number to Memory array //Incrementing MemoryIndex by one //Storing the calculation in the result variable (Rounding the result) //Adding result to Memory and ResultMemory //Incrementing the navigator by one and setting the navigator on this side to the new value //User cannot delete last number of the result, setting NoCalculationsYet to false as we've just calculated CurrentNumber = Convert.ToDouble(TbInputNumbers.Text); Calculations.AddToMemory(CurrentNumber); Result = Calculations.Summarize(LastOperatorUsedByUser); Calculations.IncrementMemoryIndexByOne(); Math.Round(Result, 10); Calculations.AddToMemory(Result); Calculations.AddToResultMemory(Result); Calculations.IncrementResultMemoryIndexByOne(); Calculations.GiveBackResultMemoryValues(); Calculations.IncrementResultMemoryNavigatorByOne(); UserCanDeleteLastNumber = true; NoCalculationsYet = false; //Setting this variable to false as the user can use division or multiplication, because the Memory array is not empty NewCalculation = false; //Setting the ResultMemory textblocks's text to the result TbResultMemory.Text = Result.ToString(); //After the calculation this variable will always be one CalculationIsOnGoing = 1; //Setting the TbCalculationProgress's text to default TbCalculationProgress.Text = ""; //Setting the TbInputNumbers Textblock's text to default after every calculation TbInputNumbers.Text = "0"; }