【问题标题】:TI-BASIC while-loop runs only once on TI-84+ CE, even though its condition is metTI-BASIC while 循环仅在 TI-84+ CE 上运行一次,即使其条件已满足
【发布时间】:2019-02-17 03:52:41
【问题描述】:

我正在尝试在我的 TI-84+ CE 上编写一个程序,让用户可以轻松地使用以 12 为底的数字进行计算。基本思想是当程序运行时,计算器可以像普通计算器一样使用,并且用户的输入在他们键入时显示。该程序接收一个以 12 为基数的字符串输入,并将字符串中的所有数字转换为以 10 为基数。我一直在编写代码片段,所以这只是最终产品的一部分。我有一段代码,它采用包含数字和以下运算符(如果存在)的输入字符串的子字符串,根据子字符串中的数字计算 base-10 值,然后将该值与运算符连接起来在子字符串中到第三个字符串,我计划稍后使用 String>Expression 方法。问题是这段代码所在的while循环只能工作一次!我什至尝试在循环结束时显示三个字符串,无论如何,它们只显示一次!例如,“5*9A-6”将 Str1 显示为“9A-6”,将 Str2 显示为“5/”,将 Str3 显示为“5/”。在循环的第一次迭代结束时,Str1 的长度明显大于 0 (4),但 while 循环没有运行。有谁知道问题是什么或如何解决?

附:我在此处粘贴的不是“问题代码”的代码部分可能在语法上并不完全正确,因为我在谷歌文档中计划我的代码,但希望很容易看出它的目的是什么。不过,有问题的那段代码非常忠实于我在计算器上写​​的内容。

ClrHome
While 1
“ “→Str1
getKey→E
While not(E=105)
getKey→E
If E=104: Str1+”-”→Str1
If E=102: Str1+toString(0) →Str1
If E=92: Str1+toString(1) →Str1
If E=93: Str1+toString(2) →Str1
If E=94: Str1+toString(3) →Str1
If E=82: Str1+toString(4) →Str1
If E=83: Str1+toString(5) →Str1
If E=84: Str1+toString(6) →Str1
If E=72: Str1+toString(7) →Str1
If E=73: Str1+toString(8) →Str1
If E=74: Str1+toString(9) →Str1
If E=41: Str1+toString(A) →Str1
If E=42: Str1+toString(B) →Str1
If E=95: Str1+toString(+) →Str1
If E=85: Str1+toString(-) →Str1
If E=75: Str1+toString(*) →Str1
If E=65: Str1+toString(/) →Str1
If E=55: Str1+toString(^) →Str1
ClrHome
Disp Str1
End
sub(Str1, 2, length(Str1)-1→Str1
“ “ →Str3
//HERE IS THE WHILE-LOOP IN QUESTION
While length(Str1)>0
inString(Str1, “+” →U :If U=0: length(Str1→U
inString(Str1, “-” →V :If U=0: length(Str1→U 
inString(Str1, “*” →W :If U=0: length(Str1→U
inString(Str1, “/” →X :If U=0: length(Str1→U 
inString(Str1, “^” →Y :If U=0: length(Str1→U 
sub(Str1, 1, min({U, V, W, X, Y→Str2 
length(Str2) →G
length(Str2) →H
If G+1>H: Then: str1=””
Else: sub(Str1, G+1, H-G→Str1 
12→A
G-inString(Str2, “.”)-1→B 
0→D
For(N,1, G-1
0→F
sub(Str2, N, 1→Str4
If not(Str4=”.”): B-1→B
If Str4=”1”:1→F
If Str4=”2”:2→F
If Str4=”3”:3→F 
If Str4=”4”:4→F 
If Str4=”5”:5→F 
If Str4=”6”:6→F 
If Str4=”7”:7→F
If Str4=”8”:8→F 
If Str4=”9”:9→F
If Str4=”A”:10→F
If Str4=”B”:11→F
(F*(A^B))+D→D
End
Str3+toString(D)+sub(Str2, length(Str2), 1→Str3 
If sub(Str3, 1, 1)=” “:sub(Str3, 2, length(Str3)-1→Str3 
Disp "String 1: "+Str1
Disp "String 2: "+Str2
Disp "String 3: "+Str3
End

【问题讨论】:

  • 感谢重定向!

标签: ti-basic


【解决方案1】:

您缺少End 语句,因此While 循环永远不会循环回到顶部。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    相关资源
    最近更新 更多