TI-Basic Z80 Programming/Input
Input functions accept data from the calculator's user. Input and output functions can be found under Template:TI-Basic/Key I/O.
Input
[[../List of Commands/Input|Input]] (Template:TI-Basic/Key I/O 1) accepts both keyboard and graph point data.
Template:Bcode:Syntax Input without a variable will open the current graph and pause the program. The arrow keys can be used to move the cursor. When Template:TI-Basic/Key is pressed, the variables X and Y will be updated with the X,Y position of the cursor. In PolarGC mode, R and θ will be updated instead.
If a variable follows Input, the program will accept a value from the keyboard and store it in the variable when Template:TI-Basic/Key is pressed.
If the format Input "string",variable is used, the calculator will display up to 16 user-defined characters before accepting input. If Strn is used, Strn is string number n, accessed with Template:TI-Basic/Key 7 n. Note that "text" must be contained in quotation marks (Template:TI-Basic/Key ["]).
Examples
This code returns the X,Y coordinates of the graph cursor: Template:Bcode:Example This code accepts a value from the keyboard, stores it in the variable called A, and displays it: Template:Bcode:Example This code displays what the program is looking for, accepts and stores a numeric value from the keyboard in the variable called A. Then A is displayed: Template:Bcode:Example
Prompt
[[../List of Commands/Prompt|Prompt]] (Template:TI-Basic/Key I/O 2) gets user input for one or more variables at a time. It displays the variable name followed by =? for each variable, waiting for keypad input followed by Template:TI-Basic/Key before continuing. Each value entered is stored in its respective variable.
Template:Bcode:Syntax
Prompt is useful for quick user input, but should be avoided due to the limitation that only the variable name can be displayed.
Examples
Displays the following: Template:Bcode:Output
Template:Bcode:Example Displays the following (with user input):
You try it!
Try these examples to practice getting and handling user input.
Pythagorean Theorem
The Pythagorean Theorem states that, for any right triangle with legs A and B and hypotenuse C, . Write a simple program that can calculate the hypotenuse C given values A and B, and display it to the screen. You can use the Input or Prompt commands. Template:Collapse top Because , .
Using Prompt: Template:Bcode:Example Using Input: Template:Bcode:Example Template:Collapse bottom
Greeting
Write a program that asks the user what their name is, and respond, using their name. Template:Collapse top Template:Bcode:Example This would appear as (with user input): Template:Bcode:Output Template:Collapse bottom Template:BottomNav
Age Calculator
Write a program the allows the user to enter their age in years, then display their age in hours, then in minutes, then in seconds. Template:Collapse top Template:Bcode:Example Template:Collapse bottom