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

In most programming languages, you can mix and match strings with variables during output. However, I cannot find a good way to do this. 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, he finishes printing as follows:

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

This is not what I want. I would like to be able to print C = √(34) , but currently I can not find a way to mix variables and strings. Any help would be appreciated.

+5
source share
5 answers

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

 Disp "foo"+" "+"bar" 

It will display:

 "foo bar" 

You should remember that to convert numbers to strings, use string() , though:

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

It will display:

 "C=√(34)" 

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

+2
source

I know this is a little late, but it can help others as well. In this case, the Output command (command) will be used. 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 
+5
source

Unfortunately, the string command proposed by PGmath does not exist on Ti-83/84/85/86. Actually there is no function to convert a number to a string.

But here you can find a possible solution: http://tibasicdev.wikidot.com/number-to-string2

+3
source

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

 Disp "Variable C: "+toString(C 

Make sure your calculator uses this version, although otherwise it will be difficult for you to find this command.

+2
source

I know this topic is very dead, but for posterity:

If you have TI-84 + CE in 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, just 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 
0
source

Source: https://habr.com/ru/post/1204769/


All Articles