This is my 2 step math equation solver: Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox2.Text = "x" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ComboBox1.Text = "+" Then Dim a Dim b Dim c Dim d a = TextBox1.Text b = TextBox3.Text c = TextBox4.Text d = c - b MsgBox(d / a) Else End If If ComboBox1.Text = "-" Then Dim n Dim f Dim g Dim h n = TextBox1.Text f = TextBox3.Text g = TextBox4.Text h = g + f MsgBox(h / n) End If End Sub End Class Code (markup): When i use the subtraction sign, i get a wrong answer. why is this?
For a start lets do some basic cleaning up: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As Single = Single.Parse(TextBox1.Text) Dim b As Single = Single.Parse(TextBox3.Text) Dim c As Single = Single.Parse(TextBox4.Text) Dim result As Single If ComboBox1.Text = "+" Then result = (c - b)/a Else If ComboBox1.Text = "-" Then result = (c + b)/a End If MsgBox(result.toString) End Sub Code (markup): Can you explain whats meant to be going on? Because "-" doesn't mean "(c + b)/a" to me, it usually means a-b=c.
in the equation, lets say it is 2x-6=4. you would add the 6 to both sides. this would give you 2x = 10 then you divide both sides by 2 answer = 6 a=2 b=6 c=4
It works now, but when I was using it with the subtraction sign, it would just add the two numbers as in putting them next to each other ex 1x - 2 = 2 answer would be 22 and idk why