|
Post by B+ on Mar 11, 2020 17:42:59 GMT
Is this homework?
Try x1 = (-b + SQR(b^2 - 4*a*c))/(2*a) and x2 = (-b + SQR(b^2 - 4*a*c))/(2*a)
But you better check D = b^2 - 4*a*c > 0 first because SQR doesn't do negative SQR's because that needs imaginary numbers.
|
|
ntech
Junior Member
Posts: 99
|
Post by ntech on Mar 11, 2020 18:33:02 GMT
It's straightforward if you hard code it, but to parse a string containing a quadratic equation is hard.
|
|
|
Post by tenochtitlanuk on Mar 11, 2020 19:11:39 GMT
|
|
|
Post by tsh73 on Mar 11, 2020 20:12:02 GMT
but to create GUI with freeform with boxes for 'a', 'b' and 'c' is easy ' Form created with the help of Freeform-J v.261006 ' Generated on Mar 11, 2020 at 23:05:29
nomainwin
WindowWidth = 520 WindowHeight = 405
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "a", 26, 16, 25, 20 statictext #main.statictext2, "b", 134, 16, 32, 20 statictext #main.statictext3, "c", 246, 16, 32, 25 textbox #main.a, 22, 46, 100, 25 textbox #main.b, 134, 46, 100, 25 textbox #main.c, 246, 46, 100, 25 button #main.button7, "Solve!", [button7Click], UL, 366, 21, 120, 45 texteditor #main.log, 22, 86, 472, 255 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "Quadratic equation solver" for window_nf as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
print #main.a, 1 print #main.b, 0 print #main.c, -1
wait
[quit.main] Close #main END
[button7Click] 'Perform action for the button named 'button7' 'Insert your own code here #main.a "!contents? a" #main.b "!contents? b" #main.c "!contents? c"
print #main.log, "";a;"*x^2";"+";b;"*x";"+";c;"=0" print #main.log,"you solve it" wait
|
|
ice
New Member
Posts: 10
|
Post by ice on Mar 12, 2020 5:33:14 GMT
Is this homework? Try x1 = (-b + SQR(b^2 - 4*a*c))/(2*a) and x2 = (-b + SQR(b^2 - 4*a*c))/(2*a) But you better check D = b^2 - 4*a*c > 0 first because SQR doesn't do negative SQR's because that needs imaginary numbers. Yes, it was homework.
|
|
ice
New Member
Posts: 10
|
Post by ice on Mar 12, 2020 5:34:17 GMT
Thank You. This helped a lot.
|
|
|
Post by B+ on Mar 12, 2020 14:35:55 GMT
Oops x2 above is same and x1, sorry I copied x1 to make x2 but forgot to replace the pos sign with neg sign right after -b.
Should be x2 = (-b - SQR(b^2 - 4*a*c))/(2*a)
Hey looks like tsh73 has all the hard work done for you getting setup on JB, just plug in formulas and program it to write answers in the Text Editor.
Man I wish I had JB when I was taking math classes :-))
|
|