Question

Create a 'simple' calculator. The calculator should be able to add, subtract, multiply, and divide two...

Create a 'simple' calculator. The calculator should be able to add, subtract, multiply, and divide two numbers.

You can use whatever format you want to receive the numbers (such as textboxes). You also can use whatever method (such as a button for each operation +, -, *, /) to determine what operation the user wants to accomplish.

The output should be displayed in a similar format to "1 + 2 = 3" or "1 - 2 = -1".

Make sure to use meaningful variable names. Make sure to give your application a meaningful name like"myCalculator". Make sure to change the form name to something meaningful. Include comments in your program that has your name and the assignment number.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the solution:

Public Class myCalculator

    Private Sub myCalculator_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CenterToScreen() 'display in center to screen
    End Sub

    Private Sub btnCalcule_Click(sender As Object, e As EventArgs) Handles btnCalcule.Click
        Dim total As Double = 0 ''declare total variable
        txtAnswer.Text = "" ''set the answer textbox to empty
        Dim no1, no2 As Integer 'declare no1 and no2 variable
        If Not Int32.TryParse(txtNumber1.Text, no1) Then 'chcek for the integer value 1
            MessageBox.Show("Number 1 is not integer")
        ElseIf Not Int32.TryParse(txtNumber2.Text, no2) Then 'chcek for the integer value 2
            MessageBox.Show("Number 2 is not integer")
        ElseIf rbtnAdd.Checked = True Then 'check if Add button is selected
            total = no1 + no2
            txtAnswer.Text = no1 & " + " & no2 & " = " & total
        ElseIf rbtnSub.Checked = True Then 'check if Subtract button is selected
            total = no1 - no2
            txtAnswer.Text = no1 & " - " & no2 & " = " & total
        ElseIf rbtnMul.Checked = True Then 'check if Multiply button is selected
            total = no1 * no2
            txtAnswer.Text = no1 & " * " & no2 & " = " & total
        ElseIf no2 = 0 Then 'check if the second number is zero
            MessageBox.Show("Number can not divided by 0")
        ElseIf rbtnDiv.Checked = True Then 'check if Divide button is selected
            total = no1 / no2
            txtAnswer.Text = no1 & " / " & no2 & " = " & total
        Else
            MessageBox.Show("Select for calculation") 'error if not selected operation
        End If
    End Sub
End Class

output:

Add a comment
Know the answer?
Add Answer to:
Create a 'simple' calculator. The calculator should be able to add, subtract, multiply, and divide two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT