What Are Simple Turing Commands For User Input?

Some software runs all by itself without any human interaction. Most programs, however, do require user input. Turing has a very simple command to get user input – get!

Once a variable has been declared (see What’s So Important About Turing Variables?), it needs a value. User input is one way to assign or store a value into a variable.

Turing User Input

Users need to know what you want them to enter, so the first thing your program should do is tell them exactly what to type in.

Say you’re converting money from dollars to cents:

cents:= dollars * 100 

That sounds pretty simple, right?

Let’s ask the user to enter the dollar amount and then store the input in an integer variable named dollars:

turing-user-input

No problem, right?

** WRONG **

turing-user-input-string-crash

Five is 5, Isn’t It?

How many ways can someone type in a dollar amount?

  • 5
  • 5.0
  • five
  • five dollars

and so on.

What did we forget to do? Ask for the value as an integer!

turing-integer-user-input-prompt

Now, this is a bit clearer for the user. If they enter anything else the program will still crash, but at least we tried to explain what the input value should be.

What About String Input In Turing?

Turing does treat strings a bit differently.

turing-string-user-input

The nice thing about this get command is that it will only store one name! If it encounters a blank space, Turing just ignores it.

turing-user-input-single-string

The bad thing about this get command is it only stores a single string or word!

I know, you just can’t win, right?

turing-string-user-input-output-example

As with the previous code example, the variable only stores the first word of a sentence.

But, there’s a little syntax trick! Add some code, and you can store an entire sentence in a variable!

turing-full-string-user-input

Now, it will store the characters until the <ENTER> key is pressed.

turing-full-string-output-example

All we needed to do was add a colon and an asterisk (or star) at the end.

There Are Always Limits!

One of Turing’s drawbacks is that it was written in the 1980s. There were RAM size limitations back then, so the programmers limited Turing’s storage capabilities. 

An integer value can be from -2147483647 to 2147483647. Turing uses 8-byte floating-point representation for real numbers, which provides 14 to 16 decimal digits of precision and an exponent range of at least -38 .. 38. Finally, strings cannot be more than 256 characters.

While these ranges aren’t bad, current languages far exceed these limitations.