Reputation: 13
So I have a program on my TI-84 calculator that calculates the volume of 3-D shapes. Here is the code
ClrHome
Disp "Z=Cuboid
Disp "Y=Tri Prism
Disp "X=Square Pyramid
Disp "W=Tri Pyramid
Disp "V=Cylinder
Disp "U=Cone
Disp "T=Sphere
Prompt S
Pause
If S=Z
Then
Prompt W,L,H
W*L*H→θ
ClrHome
Disp "V=
Disp θ
Pause
ClrHome
Stop
End
If S=Y
Then
Prompt A,B,C,H
*formula*→θ
ClrHome
Disp "V=
Disp θ
Pause
ClrHome
Stop
End
If S=X
Then
Prompt H,L,W
*formula*→θ
ClrHome
Disp "V=
Disp θ
Pause
ClrHome
Stop
End
This is my whole programs for now, the question is that when I enter the value for S as X, (S=X) and press enter to continue, the program goes into If S=Y and asks me for A,B,C,and H. If I enter S=Z, then the program goes to S=Z no problem. If I enter S=Y, program goes into S=Y no problem. But when I enter S=X, the program goes into S=Y. Why?
Upvotes: 1
Views: 64
Reputation: 64904
It working at all is more or less accidental. This code relies on the values of the variables X
, Y
, Z
etc to be different so they can be told apart. This is obviously a very fragile design.
Since this is a menu, you may be interested in the Menu(
command:
Menu("Select Shape","Cuboid",C,"Tri Prism",TP,"Square Pyramid",SP
Lbl C
Prompt W,L,H
W*L*H
Disp Ans
Stop
Lbl TP
Prompt A,B,C,H
"dunno
Disp Ans
Stop
Lbl SP
Prompt H,L,W
"dunno
Disp Ans
I put the formula "bare" and then Disp Ans
here so that the user can easily use the answer in subsequent calculations, without needlessly overwriting some variable.
Upvotes: 1