Display variable and string on same line (TI-Basic)

拟墨画扇 提交于 2019-12-06 02:13:49

问题


In most programming languages, you can mix and match strings with variables during output. However, I can't seem to find a good way to do so. Here is my code:

Prompt A,B
√(A^2+B^2)->C
If iPart(C)≠C
Then
Disp "C = √(",C
Else
Disp "C = ",C
End
Goto ED

Label ED

Unfortunately, with this code, it ends up printing like so:

A? 3
B? 5
C = √(
              34
            Done

This is not what I want. I would love to be able to have it print C = √(34), but I currently can't find any way to mix variables and strings. Any help would be appreciated.


回答1:


In ti-basic for the ti-83 the plus (+) is used to concatenate strings. Like this:

Disp "foo"+" "+"bar"

Will output:

"foo bar"

You must remember to convert numbers to strings using string() though:

Disp "C=√("+string(c)+")"

Will output:

"C=√(34)"

Disp "C=√("+c+")" (no string()) will throw an error.




回答2:


I know this is a little late, but it might help others as well. The Output( command would be used in this case. The home display is 8x16, so

Prompt A,B
√(A^2+B^2)->C
If iPart(C)≠C
Then
Disp "C = √(",C
Output(3,7,C
Else
Disp "C = ",C
End



回答3:


Unfortunatelly the "string" command suggested by PGmath doesn't exist on the Ti-83/84/85/86. Actually there is no function for converting a number into a string.

But a possible solution is given here: http://tibasicdev.wikidot.com/number-to-string2




回答4:


Since version 5.2.0 the ti-83 and 84 (possibly others as well) got the toString( command which can be used to turn a variable into a string. This piece of code will display the variable C with the correct text on the screen.

Disp "Variable C: "+toString(C

Make sure your calculator is using this version though, otherwise you're going to have a hard time finding this command.




回答5:


I know this thread is very dead but for posterity:

If you have a TI-84+CE on version 5.2 or later, you can use the toString( function. If you do not, if the output string will always be the same size, simply use Output(. If this does not generate the desired effect, you can use:

:{0,.5,1→L₁
:NL₁→L₂
:Med-Med Y₁
:Equ►String(Y₁,Str1
:sub(Str1,1,length(Str1)-3→Str1


来源:https://stackoverflow.com/questions/26391781/display-variable-and-string-on-same-line-ti-basic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!