1

So I'm writing a TI-BASIC algorithm for my calculator that does ratios. Here is the code:

Disp "GIVE ONE NUMBER"
Prompt A
Disp "GIVE A SECOND NUMBER"
Prompt B
While fPart(A)≠0 or fPart(B)≠0
A*10->A
B*10->B
End
gcd(A,B)->C
Disp A/C
Disp B/C

It seems to work in most cases. Are there any flaws/corner cases of this code that I have not noticed? Thanks.

Someone
  • 428
  • 5
  • 17
  • I also like the name. The Fight Club movie was terrible though. – Someone Jun 13 '13 at 22:29
  • When I saw this tagged `ti-basic` my mind instantly rushed back to my childhood TI-99/4A with its `CALL SOUND` and Parsec. Was disappointed to see this was a graphing calculator post. Sigh. – Mike Christensen Jun 13 '13 at 22:33
  • @Someone All the ways you wish you could be, that's me. I look like you wanna look, I screw like you wanna screw, I am smart, capable, and most importantly, I am free in all the ways that you are not. – Tyler Durden Jun 13 '13 at 22:33
  • Sorry to disappoint :) – Someone Jun 13 '13 at 22:40

2 Answers2

2

It will work, but there is an even cooler way to do it with no loops.

Disp "GIVE ONE NUMBER"
Prompt A
Disp "GIVE A SECOND NUMBER"
Prompt B
1/fPart(A)->F
A*F->A
B*F->B
1/fPart(B)->F
A*F->A
B*F->B
gcd(A,B)->C
Disp A/C
Disp B/C
Jean-Bernard Pellerin
  • 12,556
  • 10
  • 57
  • 79
1

Yes it will work and so will Jean-Bernard Pellerin's answer, but to best clean it up:

Input "GIVE ONE NUMBER",A
Input "GIVE A SECOND NUMBER",B
1/fPart(A)->F
A*F->A
B*F->B
1/fPart(B)->F
A*F->A
B*F->B
gcd(A,B)->C
Disp A/C
Disp B/C
Moshe Goldberg
  • 461
  • 2
  • 15