# CDC Community

πΉ Historical Conservation πΉ

### Site Tools

tutor:showing_variable_values

# Showing the Value of a Variable

We have learned how to calculate and how to store results in variables. How do we show these results on the screen? Suppose we perform this calculation:

calc yβ¦5sqrt(37) \$\$ or, yβ¦5x371/2 ; "sqrt" means square root

How do we later show the value of y? Assume we have defined y. Perhaps we could use this:

write y

No, that won't work; that will just put the letter βyβ on the screen. The -write- command is basically a device for displaying non-varying text, not for showing the value contained in a variable. We need another command:

show y

This will show the value of y in an appropriate format (-show- picks an appropriate number of significant figures and will use a scientific format such as 6.7Γ1013, if the number is large enough to require it). By using -show- instead of -write-, you tell TUTOR that you want the stored value to be shown rather than just the characters in the tag.

The -show- command will normally choose 4 significant figures, so that a typical display might be β-23.47β. You can specify a different value by giving a second βargumentβ (arguments are the individual pieces of the tag of a statement):

show y,8 \$\$ 8 significant figures

The arguments of the -show- command can, of course, be complicated expressions:

show 10+30cos(2angle),format+2)

In fact, it is a general rule that you can use complicated expressions anywhere in TUTOR statements. For example, ''draw 5rad +225,34L;123-L2,28Lβ!

Here is a short program which uses -show- to display a table (see Figure 4-6) of square roots of the integers from 1 to 15:

define N=v1 unit roots at 310 \$\$ write titles for the two columns write N at 325 write N1/2 do root,Nβ1,15 * unit root at 410+100N show N at 425+100N show sqrt(N)

The last statement could also be written as βshow NWβ. 'This technique of making tables, including the use of the -do- index (N) to position the displays (as in βat 425Β±100Nβ) is an important and powerful tool.

There are other commands for displaying variables: -showe- (exponential), -showt- (tabular), -showa- (alphanumeric), -showo- (octal), and -showz- (show trailing zeroes). These are described in detail in the reference material mentioned in Appendix A.

Although -write- is basically designed for non-variable text, combinations of text and variables occur so often that TUTOR makes it easy to βembedβ a -show- command within a -write-:

write The area was βs,13.7w,6β square miles.

The embedded βsβ indicates a -show- command and the remainder β13.7w,6β is its tag. Other permissible abbreviations include βoβ (showo), βaβ (showa), βeβ (showe), βtβ (showt) and βzβ (showz). The above -write- statement is equivalent to:

write The area was show 13.7w,6 write square miles.