Never work on an SSS triangle again!

I've created a program to solve any triangle given its three sides.
Using the law of cosines and the law of sines, this program will output the angles of any triangle.

Code:
``` "The SSS "Triangle Solver! "Made By "Erica DiGiulio //Get variables Input "Side a=",A Input "Side b=",B Input "Side c=",C //Testing if the triangle is valid If A+B<=C or A+C<=B or B+C<=A or A<=0 or B<=0 or C<=0 Then Disp " " Disp "Not a valid" Disp "Triangle" Stop End //Testing for equilateral triangles If A=B and B=C Then Disp " " Disp "All angles are" Disp "60^^o" Stop End //Testing for isosceles trianges If A=B or A=C or B=C Then Goto 3 Else Goto 4 End //Isosceles solver Lbl 3 If A=B Then cos^-1(((C/2)/A)->H H->G 180-(H+G)->I End If A=C Then cos^-1(((B/2)/A)->I I->G 180-(I+G)->H End If C=B Then cos^-1(((A/2)/C)->H H->G 180-(H+I)->G End Goto 42 //Testing for longest side Lbl 4 If A>B and A>C Then Goto 6 Else Goto 5 End Lbl 5 If B>C and B>A Then Goto 7 Else Goto 8 End //Calculating angles //Variables will be saved ABC->GHI and then will be converted back Lbl 6 cos^-1(((B^^2+C^^2-A^^2)/(2BC))->G sin^-1(((B/A)*(sin(G))->H 180-(G+H)->I Goto 42 Lbl 7 cos^-1(((A^^2+C^^2-B^^2)/(2AC))->H sin^-1(((A/B)*(sin(H))->G 180-(G+H)->I Goto 42 Lbl 8 cos^-1(((A^^2+B^^2-C^^2)/(2AB))->I sin^-1(((A/C)*(sin(I))->G 180-(I+G)->H Goto 42 //Display the answer Lbl 42 round(G,2)->A round(H,2)->B round(I,2)->C Disp " " ClrHome Output(2,2,"Angle A: ") Output(2,11,A) Output(3,2,"Angle B: ") Output(3,11,B) Output(4,2,"Angle C: ") Output(4,11,C) Disp " " Disp " " Disp " " Disp " " Disp " " Stop ```
May I suggest, from looking at your code,using an Output( comand?
Unicorn wrote:
May I suggest, from looking at your code,using an Output( comand?

I'm using output for the last parts because it won't fit otherwise, but I don't think the other ones really need it.
why not using the simple cosine rule:
a^2=b^2+c^2-2bc cos(alpha)
?

I created a simple new program, without comments etc. but even faster First my code checks whether the triangle is possible, Triangle Inequality Theorem. Then it calculates two angles using the cosine rule, the third angle is 180-A-B
Here it is:

Code:
``` Degree Input "Side a=",A Input "Side b=",B Input "Side c=",C If A+B>C and A+C>B and B+C>A Then cos^-1(.5B^^-1C^^-1(B^^2+C^^2-A^^2->G cos^-1(.5A^^-1C^^-1(A^^2+C^^2-B^^2->H 180-G-H->I round(G,2->A round(H,2->B round(I,2->C ClrHome Output(2,2,"Angle A: Output(2,11,A Output(3,2,"Angle B: Output(3,11,B Output(4,2,"Angle C: Output(4,11,C Return Else Disp " ","Not a valid","Triangle Return End ```
PT_ wrote:
why not using the simple cosine rule:
a^2=b^2+c^2-2bc cos(alpha)
?

I created a simple new program, without comments etc. but even faster First my code checks whether the triangle is possible, Triangle Inequality Theorem. Then it calculates two angles using the cosine rule, the third angle is 180-A-B
Here it is:

Code:
``` Degree Input "Side a=",A Input "Side b=",B Input "Side c=",C If A+B>C and A+C>B and B+C>A Then cos^-1(.5B^^-1C^^-1(B^^2+C^^2-A^^2->G cos^-1(.5A^^-1C^^-1(A^^2+C^^2-B^^2->H 180-G-H->I round(G,2->A round(H,2->B round(I,2->C ClrHome Output(2,2,"Angle A: Output(2,11,A Output(3,2,"Angle B: Output(3,11,B Output(4,2,"Angle C: Output(4,11,C Return Else Disp " ","Not a valid","Triangle Return End ```

That's pretty much what I did, but in a different order. Also, don't you have to apply this rule to the longest side? I thought that was necessary.

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum