Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

TI-Basic Z80 Programming/Input

From Wikibooks, open books for an open world
<TI-Basic Z80 Programming

Input functions accept data from the calculator's user. Input and output functions can be found underPRGMI/O.

Input

[edit |edit source]

Input (PRGMI/O 1) accepts both keyboard and graph point data.

Input [variable]Input ["text",variable]Input [Strn,variable]no arguments
  • If no variable is passed,Input will open the graph and the user will select a point by using the arrow keys andENTER.
  • If a variable is passed,Input will store the user's input into this variable.
  • If a string or text is provided with the variable, the text will be displayed and the user input will follow on the same line.

Input without a variable will open the current graph and pause the program. The arrow keys can be used to move the cursor. WhenENTER is pressed, the variablesX andY will be updated with theX,Y position of the cursor. InPolarGC mode,R andθ will be updated instead.

If a variable followsInput, the program will accept a value from the keyboard and store it in the variable whenENTER is pressed.

If the formatInput "string",variable is used, the calculator will display up to 16 user-defined characters before accepting input. IfStrn is used,Strn is string numbern, accessed withVARS 7n. Note that"text" must be contained in quotation marks (ALPHA ["]).

Examples

[edit |edit source]

This code returns theX,Y coordinates of the graph cursor:

Input
Disp X,Y

This code accepts a value from the keyboard, stores it in the variable calledA, and displays it:

Input A
Disp A

This code displays what the program is looking for, accepts and stores a numeric value from the keyboard in the variable calledA. ThenA is displayed:

Input "APPLES",A
Disp A

Prompt

[edit |edit source]

Prompt (PRGMI/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 byENTER before continuing. Each value entered is stored in its respective variable.

Prompt variableA[,variableB,...,variable n]

Prompt is useful for quick user input, but should be avoided due to the limitation that only the variable name can be displayed.

Examples

[edit |edit source]
:Prompt A:Disp "VALUE IS",A


Displays the following:

A?=5Value is5

:Prompt M,G,H:Disp "PE =",M*G*H

Displays the following (with user input):

M?=5G?=9.81H?=2PE =            98.1

You try it!

[edit |edit source]

Try these examples to practice getting and handling user input.

Pythagorean Theorem

[edit |edit source]

The Pythagorean Theorem states that, for any right triangle with legs A and B and hypotenuse C,A2+B2=C2{\displaystyle A^{2}+B^{2}=C^{2}}. Write a simple program that can calculate the hypotenuse C given values A and B, and display it to the screen. You can use theInput orPrompt commands.

Solution

BecauseA2+B2=C2{\displaystyle A^{2}+B^{2}=C^{2}},C=A2+B2{\displaystyle C={\sqrt {A^{2}+B^{2}}}}.

UsingPrompt:

:ClrHome:Prompt A,B:√(A^2+B^2)→C:Disp "C = "+C
* Note: It is also acceptable to use twoPrompt commands: one for each variable. But, by combining them into one command, several bytes are saved.

UsingInput:

:ClrHome:Input "A = ",A:Input "B = ",B:√(A^2+B^2)→C:Disp "C = "+C
* Note: The text argument of theinput commands is arbitrary as it does not the affect the value of the user input.

Greeting

[edit |edit source]

Write a program that asks the user what their name is, and respond, using their name.

Solution
:ClrHome:Disp "TYPE YOUR NAME":Input "NAME: ",Str1:Disp "HI, "+Str1+" I'M":Disp "YOUR TI-84!"

This would appear as (with user input):

TYPE YOUR NAMENAME: JACOBHI, JACOB I'MYOUR TI-84!


Previous:Output
Next:Conditional Statements
Table of Contents:TI-Basic Z80 Programming

Age Calculator

[edit |edit source]

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.

Solution
Input "AGE? ",A
ClrHome
Disp "HOURS",A*365*24
Disp "MINUTES",A*365*24*60
Disp "SECONDS",A*365*24*60*60
Retrieved from "https://en.wikibooks.org/w/index.php?title=TI-Basic_Z80_Programming/Input&oldid=4057692"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp