Ok, here's my problem. I wrote an advanced Pythagorean Theorem program, but it apparently is having exceptions. Here's an instance of my problem. When I input A? √(3)
and B? 2
, I get 0
back. Here's the code:
:Prompt A,C
:(C^2-A^2)->B
:If B<0
:Then
:Disp "THAT IS N
OT A VALID TRIA
ANGLE
:Else
:If iPart(√(B))≠
√(B)
:Then
:Disp "B = √(",B
:Else
:Disp "B = ",√(B)
:End
:End
Therefore, if B = 1, then hypothetically it should output B = 1
but instead it outputs:
A=? √(3)
C=? 2
B = √(
1
Done
What am I doing wrong and how can I fix it?
When I quickly evaluate your program, it seems to work correctly when you get B≠1
. For example if I want to calculate the famous 3,4,5 - triangle it shows:
A=?4
C=?5
B=
3
Done
Apparently the iPart(
doesn't work correctly with √(1)
. You could include an extra statement to the If iPart( ...
statement to rule this out. Like this.
:...
:If iPart(√(B))≠√(B) and B≠1
:...
Besides that I think the program looks cleaner and nicer if you use the Input
, ClrHome
and Output(
commands.
:ClrHome
:Input "A: ",A
:Input "C: ",C
:(C^2-A^2)->B
:If B<0
:Then
:Output(4,1,"THA
T IS NOT A")
:Output(5,1,"VAL
ID TRIANGLE")
:Else
:If iPart(√(B))≠
√(B) and B≠1
:Then
:Output(3,1,"B:
√( )")
:Output(3,5,B)
:Else
:Output(3,1,"B:")
:Output(3,5,√(B))
:End
:End
:Pause
:ClrHome
Now the results screen looks something like this:
A: √(3)
C: 2
B: 1
I think this is cleaner, with the 3
aligned istead of in the bottom right corner. When you press ENTER everything will remove itself from the screen (due to the Pause
command).