151
TI 68K / 89 Basic Tutorial
« on: June 17, 2005, 07:37:00 pm »
Chapter 2: A closer look at input functions.
Online dating services are designed to match up the perfect guy with the perfect girl, or guy or whatever?anyway, when you go to such websites and fill out or input your information, you are asked certain question. To these questions, there is only a certain amount of possible answers (for example: are you a girl, guy, cheese steak, meatball sandwich?are you seeking a girl, guy, cheese steak or meatball sandwich?). If the dating program is any good, it will make sense of your desires and try to obtain more specific input. Input is, according to answers.com something put into a system or expended in its operation to achieve output or a result. In the case of the dating service, the output would be your date, or sandwich.
In 89 Basic, there are several different ways to acquire input from the user. The functions that will be explored in this chapter are Input and InputStr. The Dialog Box input functions will be included throughout the variable chapters.
Enter the program editor and press 3 to create a new program. Name this program ?Inputut?. Enter the program below as shown:
Inputut()
Prgm
Disp ?How good is this tutorial?, ?On a scale of 0 to 10?
Input ?Number?, x
DispHome()
Return
EndPrgm
Type in ?x? on the home screen without the quotes and you will how good you think this tutorial is. Now type GetType(x). This will return the type of variable x is. Don?t worry so much about that right now. Just remember that whatever reply you supply for input is stored as a numerical expression. That means that only numbers, and words that are numbers, can be accepted using input. If you wanted to get a response that wasn?t a number, such as a name or birthplace, you would use InputStr instead of Input:
Inputnm()
Prgm
Disp ?My name is Desmond Jenkins?, ?What is yours?
Inputstr ?My Name?, x
DispHome()
Return
EndPrgm
When you perform, GetType(x) you will notice that x is type ?STR?. This means that the users input has been turned into a string. A string is an array of characters. In other words, a string is something in quotes. A literal.
Focus: Expressions
In math x can be equal to a number. Say 5. X=5. This means that x is an expression that is equal to 5. Now y can be set to x. This means that y=x=5.
In programming this is also true. In the first example when you used Input ?Number?, x, the number that the user inputs is an expression (numerical value) from 1 to 10. X is set to that input. Therefore, x is equal whatever the person enters, say 5. Variable X is now an expression, which is equal to 5.
Focus: Strings
In English, when you quotes someone, you use ?? quotation marks. When you use quotation marks to quotes someone, you are repeating word for word what that person said. You do this even when you quote yourself.
Desmond said, ?Programming is fun?, but nobody believed him.
?Programming is fun?, is an example of a literal because it is something that I literally said.
When the processor looks at your code, it will inherently try to quantify everything try typing Disp Programming is fun see what kind of error you get. You see without the quotes, the calculator thinks that Programming is a variable name and then discovers that it couldn?t be because the file name is too long. Try typing Disp ?Programming is fun?. This works because the calculator understands that Programming is fun is what you literally want to display, not some expression stored in a variable.
Chapter Review:
What is the difference between Input and InputStr?
What is a string?
What is an expression?
Definitions
Concept of Expression ?EXPR? A mathematical variable or number. On the 89 the ?Type? of variable that a number is or a variable that contains a number.
Concept of Strings ?STR? A quote. A literal. This is how you tell the calculator to display exactly what you want, without trying to quantify it. Remember to use quotation.
GetType Evaluates what type of system type a given variable is. Try GetType(hellowd) GetType(45)
Input Used to scan expressions from the user
InputStr Used to scan strings from the user
DispHome Return to the home screen, program is still active.
Return The easiest and safest way to exit a program or function.
The executon will pick up where you left the previous program. When you use this in a function, you can return values.
Stop Full Stop. End of code execution. Dangerous. Avoid at all costs.
Extra Program: Intermediate
Info()
Prgm
ClrIO
Disp ?My name is Desmond Jenkins?, ?What is yours?
Inputstr ?My Name?, x
Input ?How old are you?, y
ClrIO
Disp ?Okay?, ?Your name is ?, x, ?and you are ?, string(y)&? Years old.?
Online dating services are designed to match up the perfect guy with the perfect girl, or guy or whatever?anyway, when you go to such websites and fill out or input your information, you are asked certain question. To these questions, there is only a certain amount of possible answers (for example: are you a girl, guy, cheese steak, meatball sandwich?are you seeking a girl, guy, cheese steak or meatball sandwich?). If the dating program is any good, it will make sense of your desires and try to obtain more specific input. Input is, according to answers.com something put into a system or expended in its operation to achieve output or a result. In the case of the dating service, the output would be your date, or sandwich.
In 89 Basic, there are several different ways to acquire input from the user. The functions that will be explored in this chapter are Input and InputStr. The Dialog Box input functions will be included throughout the variable chapters.
Enter the program editor and press 3 to create a new program. Name this program ?Inputut?. Enter the program below as shown:
Inputut()
Prgm
Disp ?How good is this tutorial?, ?On a scale of 0 to 10?
Input ?Number?, x
DispHome()
Return
EndPrgm
Type in ?x? on the home screen without the quotes and you will how good you think this tutorial is. Now type GetType(x). This will return the type of variable x is. Don?t worry so much about that right now. Just remember that whatever reply you supply for input is stored as a numerical expression. That means that only numbers, and words that are numbers, can be accepted using input. If you wanted to get a response that wasn?t a number, such as a name or birthplace, you would use InputStr instead of Input:
Inputnm()
Prgm
Disp ?My name is Desmond Jenkins?, ?What is yours?
Inputstr ?My Name?, x
DispHome()
Return
EndPrgm
When you perform, GetType(x) you will notice that x is type ?STR?. This means that the users input has been turned into a string. A string is an array of characters. In other words, a string is something in quotes. A literal.
Focus: Expressions
In math x can be equal to a number. Say 5. X=5. This means that x is an expression that is equal to 5. Now y can be set to x. This means that y=x=5.
In programming this is also true. In the first example when you used Input ?Number?, x, the number that the user inputs is an expression (numerical value) from 1 to 10. X is set to that input. Therefore, x is equal whatever the person enters, say 5. Variable X is now an expression, which is equal to 5.
Focus: Strings
In English, when you quotes someone, you use ?? quotation marks. When you use quotation marks to quotes someone, you are repeating word for word what that person said. You do this even when you quote yourself.
Desmond said, ?Programming is fun?, but nobody believed him.
?Programming is fun?, is an example of a literal because it is something that I literally said.
When the processor looks at your code, it will inherently try to quantify everything try typing Disp Programming is fun see what kind of error you get. You see without the quotes, the calculator thinks that Programming is a variable name and then discovers that it couldn?t be because the file name is too long. Try typing Disp ?Programming is fun?. This works because the calculator understands that Programming is fun is what you literally want to display, not some expression stored in a variable.
Chapter Review:
What is the difference between Input and InputStr?
What is a string?
What is an expression?
Definitions
Concept of Expression ?EXPR? A mathematical variable or number. On the 89 the ?Type? of variable that a number is or a variable that contains a number.
Concept of Strings ?STR? A quote. A literal. This is how you tell the calculator to display exactly what you want, without trying to quantify it. Remember to use quotation.
GetType Evaluates what type of system type a given variable is. Try GetType(hellowd) GetType(45)
Input Used to scan expressions from the user
InputStr Used to scan strings from the user
DispHome Return to the home screen, program is still active.
Return The easiest and safest way to exit a program or function.
The executon will pick up where you left the previous program. When you use this in a function, you can return values.
Stop Full Stop. End of code execution. Dangerous. Avoid at all costs.
Extra Program: Intermediate
Info()
Prgm
ClrIO
Disp ?My name is Desmond Jenkins?, ?What is yours?
Inputstr ?My Name?, x
Input ?How old are you?, y
ClrIO
Disp ?Okay?, ?Your name is ?, x, ?and you are ?, string(y)&? Years old.?