プレイ日記
Pikachu Squi-Volt
Finally got this. Anyways, how do I detect what the user typed, and run an if-else statement on it?
3そうだね
プレイ済み
返信[1]
親投稿
MathPRG MathProgrammer
INPUT [prompt text],var/var$ This command takes user input via the keyboard. Prompt text is optional, it is simply a string (text put in quotation marks) that can be a question to ask the user. Leave out the comma if you don't use this. Var/var$ will be the variable to which the received user input will be saved.
1そうだね
プレイ済み
返信[2]
親投稿
MathPRG MathProgrammer
The dollar sign will make the output a string, so you can get text output. Leave this out if you want a number to be received. IF condition THEN commands if true ELSE commands if false The condition is a comparison which can be an expression, basically it's what you want to use to determine the result.
1そうだね
プレイ済み
返信[3]
親投稿
MathPRG MathProgrammer
For example, IF VAR==3 THEN commands will execute the commands only if the variable equals three. To see if something is equal you use two equal signs. You can also compare to a string (IF VAR$=="TEST" THEN commands) After ELSE put the commands you want executed if the condition is not true.
1そうだね
プレイ済み
返信[4]
親投稿
MathPRG MathProgrammer
A condition is false if it returns 0. In a binary comparison the result is zero if one side of the comparison does not relate to the other side in the way specified by the operator (==,!=,>=,<=,>,<) A condition is considered true if it returns anything other than zero. This means writing something like IF VAR THEN is valid, and will execute the commands after THEN as long as VAR is not zero.
1そうだね
プレイ済み
返信[5]
親投稿
Stewart segludian1
My number guessing example code sounds like what you are looking for. You can download it by entering the key: 8E7Y33G4 Please give it a download, run, and read and let me know if you have questions.
1そうだね
プレイ済み
返信[6]
親投稿
MathPRG MathProgrammer
Oh, and ! is the NOT operator - using it on a number or variable will return the opposite output (TRUE/FALSE) When used in a condition like !=, it will invert that output as well. For example, IF VAR!=7 THEN will execute the commands after THEN as long as VAR is not 7.
1そうだね
プレイ済み
返信[7]
親投稿
MathPRG MathProgrammer
I hope my lengthy explanation isn't too complicated! Here's an example of these commands in action: INPUT "ENTER A NUMBER",NUM IF NUM!=19 THEN PRINT "YOU DID NOT ENTER 19." ELSE PRINT "YOU ENTERED 19!"
1そうだね
プレイ済み
返信[8]
親投稿
MathPRG MathProgrammer
The user will see "ENTER A NUMBER" on the console. If they type anything other than 19 and press enter, "YOU DID NOT ENTER 19." will appear on the console. If they entered 19 the program will output "YOU ENTERED 19!"
1そうだね
プレイ済み
返信[9]
親投稿
Autz sonic-HD8765
You finally got a black screen?
0そうだね
プレイ済み