5

I am trying to create a simple BASIC program for my TI-84 that will calculate the midpoint of two given points. This is my current code below, which produces an error upon trying to run the program:

:Prompt XONE,YONE,XTWO,YTWO
:((XONE+YONE)/2)->X
:((XTWO+YTWO)/2)->Y
:Disp X,Y

The reason I suspect it has something to do with my variable naming is because I tried running the same program, except I named the variables A,B,C, and D, instead of what you see above, and that ran fine.

AstroCB
  • 12,337
  • 20
  • 57
  • 73
user1726923
  • 73
  • 1
  • 3

4 Answers4

3

Some variants of TI BASIC (such as those that ship with the 68000-CPU-based devices) allow for longer variable names but the variant that ships with the TI-84 calculator only allows the variables A through Z and theta. See here for more detail.

Hence, for those, you cannot use variables like XONE as you have done in your code.

In any case, your midpoint calculation is fundamentally wrong. You currently have it averaging XONE and YONE to get the midpoint on the X-axis, whereas you should be averaging XONE and XTWO (that's of course ignoring the limitations already mentioned about allowed variable names).

In other words (assuming the variables were valid for your calculator, which they're not), it would be:

:((XONE+XTWO)/2)->X
:((YONE+YTWO)/2)->Y

With both those changes (fixing the midpoint calculation and only using allowed variable names), that would be something like:

:DISPLAY "X1:"
:PROMPT A

:DISPLAY "Y1:"
:PROMPT B

:DISPLAY "X2:"
:PROMPT C

:DISPLAY "Y2:"
:PROMPT D

:((A+C)/2)->E
:((B+D)/2)->F

:DISP E
:DISP F
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Congrats on answer #7,000! – chux - Reinstate Monica Aug 30 '13 at 03:15
  • 2
    I dont know who accepted this, but it is very wrong. TI-84 variables are limited to the ones on the calculator. It sounds like you are referring to TI-89 basic (or axe even). – Lemon Drop Oct 26 '13 at 04:34
  • 1
    -1 because your answer is simply wrong. You might be answering for some later incarnation of TI-Basic (the question only asks for TI-84) or some other language entirely. You should either edit your answer to be correct or state in your answer that it does not pertain to TI-84 TI-Basic. – ankh-morpork Feb 28 '15 at 13:35
  • @dohaqatar7, did you not actually _read_ the answer? OP apparently did, which is why I assume they accepted it. It states quite clearly the limitations on variable names for TI-84. The code that I gave was merely to demonstrate the incorrect calculation in that you need to average the two `x`s, not an `x` and `y`. However, I'll try to make that clearer so there's no possibility of future confusion. – paxdiablo Mar 01 '15 at 02:55
  • @paxdiablo, quoting from your answer ,"TI BASIC, in general, should be able to handle variables at least up to eight characters." This statement is incorrect. I know of no from of TI-Basic for which this holds true. – ankh-morpork Mar 01 '15 at 03:40
  • @dohaqatar7: http://en.wikipedia.org/wiki/TI-BASIC#Variables but, in the context of the question, it's irrelevant, so I'll remove it. – paxdiablo Mar 01 '15 at 03:48
  • 1
    @paxdiablo I now see what caused my confusion and have removed my down vote. Your statement holds true for 68k calculators (TI-89, TI-89 Titanium, TI-92, TI-92 Plus, and Voyage 200) but, the questions asked about a Z80 (TI-84) calculator. – ankh-morpork Mar 01 '15 at 12:19
  • 1
    No probs, @dohaqatar7, any other suggestions you have to improve this (or any other) answer will be gratefully received. Cheers. – paxdiablo Mar 01 '15 at 13:04
3

Generally, when declaring variables on the calculator, you want to stick to one or two characters, if possible. Up to five do work, but it is common practice to use less. If you want the user to know what the inputs are, try this:

:DISP "XONE:"
:PROMPT A
:DISP "YONE:"
:PROMPT B
:DISP "XTWO:"
:PROMPT C
:DISP "YTWO:"
:PROMPT D
:((A+C)/2)->X
:((B+D)/2)->Y
:DISP X,Y

Happy Coding!

Dave Coffman
  • 231
  • 3
  • 10
  • +1 because this is much more accurate than the current top answer; although it should be noted that list variables can have up to 5 character names on **all** forms of TI-Basic. – ankh-morpork Feb 28 '15 at 13:37
  • Instead of using `Disp "XONE:":Prompt A`, use `Input "XONE", A` – tylerr147 Sep 06 '19 at 14:22
2

You are correct, normal variables are limited in length to a single character; however, multiple character variable names can be used in other aspects of TI-Basic programming.

List Variables

List variables can be named using between between 1 and 5 characters, or using the 6 predefined list variables (L1-L6).

{1,2,3,4→ALIST

System Variables

System variables are found by pressing the VARS key on you calculator. They consists of statistical, table and, graph variables that generally consist of 3 or 4 characters. Examples of these variables include Xmin, Xmax, Ymin, Ymax, TblStart and, TblInput. Values can be stored to these variables in the same manner as normal variables.

10→Xmin

10→Xmax

Finance Variables

Finance variables function similarly to system variables. They are a set of predefined variables with multi-character names. The primary difference being that they all pertain to finance in some manner. These variables are accessed by pressing APPS, 1, Right Arrow. Examples of include I%, PV and, PMT.

10→I%

10→PV

10→PMT

This answer is based entirely off a TI-83 Plus calculator. As far as I know, this should not be an issue, but any inconstancy can be put down to this.

ankh-morpork
  • 1,732
  • 1
  • 19
  • 28
0

I like to use input for this:

Disp "(A,B)(C,D)
Input "A:",A
Input "B:",B
Input "C:",C
Input "D:",D

I have a program with this function that i will try to upload later today.

EDIT: Uploaded and available for download here.