need help with my code
-
Wednesday, October 31, 2012 4:02 AM
I am using the Fremmy(sp) Extension
My issue is that once I get down to the y/n part of my coding, I can't get it to either start from the begining or say "thanks for playing!"
I'm very new to this just getting frustrated.
Please any help would be greatly appreciated.
'ask user to guess number 1 to 10 start: TextWindow.Write("I'm thinking of a number 1-10...Gues what it is!: ") number = TextWindow.ReadNumber() random = Math.GetRandomNumber(10) If number = random Then TextWindow.WriteLine("You guessed " + number + " and the number is " + random + ". You are correct!") ElseIf number > random or number < random then TextWindow.WriteLine("You guessed " + number + " and the number is " + random + ". I'm sorry, but that is incorrect.") TextWindow.Write("Go again? (y/n): ") again = TextWindow.Read() Goto start Else TextWindow.WriteLine("Thanks for playing!") EndIf
All Replies
-
Wednesday, October 31, 2012 4:11 AM
You don't specify "If again = "y" then" and/or "Else again = "n" then" after declaring the variable "again" for use.
Your code should look something like:
'ask user to guess number 1 to 10 start: number = "" 'Using "" clears the variable random = "" again = "" TextWindow.Write("I'm thinking of a number 1-10...Guess what it is!: ") number = TextWindow.ReadNumber() random = Math.GetRandomNumber(10) If number = random Then TextWindow.WriteLine("You guessed " + number + " and the number is " + random + ". You are correct!") ElseIf number > random or number < random then TextWindow.WriteLine("You guessed " + number + " and the number is " + random + ". I'm sorry, but that is incorrect.") TextWindow.Write("Go again? (y/n): ") again = TextWindow.Read() If again = "Y" Or again = "y" Then 'Gives 2 options. If the user has CAPS on, it'll recognise it as a 'y' anyway without conversion. Goto start Else TextWindow.WriteLine("Thanks for playing!") EndIf EndIfThat code should work for you. If it doesn't, feel free to tell me and I'll troubleshoot it for you :)
I LOVE Small Basic! 'A computer without code is like a car without gasoline.' 'Just as gasoline needs a pump to get it into the car, code needs a person to enter it into a computer... That makes me feel important!' Both quotes by me
- Edited by Joman Mied Wednesday, October 31, 2012 4:31 AM Added code
- Marked As Answer by Rosco2382 Wednesday, October 31, 2012 4:39 AM
-
Wednesday, October 31, 2012 4:40 AMThank you so much, I didn't know i could use another If...then statement again inside of one. I appreciate your help.
-
Wednesday, October 31, 2012 4:44 AM
You are welcome. And, if you wanted to, you could have a hundred if statements inside one another! It is endless because all it is telling the computer to do is check if another condition is true after finding the previous condition to be true!
Again, you're welcome. If you have any other questions, feel free to ask! :P
TextWindow.Write("Do you like Small Basic? Y/N: ") yn = TextWindow.Read() If yn = "Y" Then TextWindow.WriteLine("High-Five! You are awesome!") ElseIf yn = "N" Then TextWindow.WriteLine("Deep down inside, you like Small Basic :)") EndIf

