HI There Please help me with this problem for C coding Windo
HI There!!! Please help me with this problem for C# coding:
Windows Calculator You’re going to create a Windows Form Application that mimics a calculator.
This is the screenshot how it shouldl look like.
It should have a textbox and the following buttons: + Addition - Subtraction * Multiplication / Division = Equals (Will perform the final calculation) C Clear (Will clear the text box) There will be no maximize or minimize buttons. The rules are these: 2 A user enters a number (in the app you’ll use the datatype Decimal) and they will then click an operation button. Then they can enter another number and if they press equals then you’re done and the result will be displayed. No other inputting of numbers is allowed. If they don’t press equals and instead click another operation, then clear the textbox and allow them to enter another number. They can so this as many times as they like. Once the equals button is pressed make the text box read only and disable all of the buttons (Except for C) until C (clear) is clicked and then re-enable the buttons, clear and enable the text box and allow them to start again. So, if they enter 30, then click -, then enter 5, and then press = (equals) then 25 will be displayed in the textbox. The textbox will be read-only and all of the buttons except for the C (clear) button will be disabled. Once they click C (Clear) all of the buttons will be enabled, the textbox will be enabled, and cleared. Then they can start again. If they enter 30, and the – (Minus), and then 5, and then * (Multiply), then 5, and then = (equals) then 125 will be displayed in the box that is read-only, and all of the buttons except for the C button will be disabled. In this application you’ll be coding for bad input. So if they type in anything but a valid decimal you’re going to alert them (Use a messagebox) that their input was invalid. Allow them to enter new input. Of course this will happen on the operation click (Either +, -, *, /, or =). Also, you’ll have to code for division by zero. So, if they type in a number, say 5, then / and then 0, then you’ll message box them to say 3 they cannot divide by zero. Then allow them to re-enter their input. Use Decimal.TryParse to check all numbers for validity.
decimal number; string value = \"Hello World!!!\"; if (Decimal.TryParse(value, out number)) Console.WriteLine(number); else Console.WriteLine(\"Unable to parse \'{0}\'.\", value); This example will fail. But fail gracefully and not throw an error. Instead it will just run the line: Console.WriteLine(\"Unable to parse \'{0}\'.\", value); TryParse is basically a parse statement with a built in try catch. https://msdn.microsoft.com/en-us/library/9zbda557(v=vs.110).aspx
CalculatorSolution
The following is code for calculator (tested and run successfully)
Public Class CALCULATOR
Dim total1 As Single
Dim total2 As Single
Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
txtDisplay.Text = txtDisplay.Text & btnOne.Text
End Sub
Private Sub btnThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThree.Click
txtDisplay.Text = txtDisplay.Text & btnThree.Text
End Sub
Private Sub btnFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFour.Click
txtDisplay.Text = txtDisplay.Text & btnFour.Text
End Sub
Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click
txtDisplay.Text = txtDisplay.Text & btnTwo.Text
End Sub
Private Sub btnFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFive.Click
txtDisplay.Text = txtDisplay.Text & btnFive.Text
End Sub
Private Sub btnSix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSix.Click
txtDisplay.Text = txtDisplay.Text & btnSix.Text
End Sub
Private Sub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click
txtDisplay.Text = txtDisplay.Text & btnSeven.Text
End Sub
Private Sub btnEight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEight.Click
txtDisplay.Text = txtDisplay.Text & btnEight.Text
End Sub
Private Sub btnNine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNine.Click
txtDisplay.Text = txtDisplay.Text & btnNine.Text
End Sub
Private Sub btnZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZero.Click
txtDisplay.Text = txtDisplay.Text & btnZero.Text
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDisplay.TextChanged
End Sub
Private Sub btnEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEquals.Click
total2 = total1 + Val(txtDisplay.Text)
txtDisplay.Text = total2
total1 = 0
End Sub
Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click
total1 = total1 + Val(txtDisplay.Text)
txtDisplay.Clear()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtDisplay.Clear()
End Sub
Private Sub btnSub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSub.Click
total1 = total1 - Val(txtDisplay.Text)
txtDisplay.Clear()
End Sub
Private Sub CALCULATOR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class


