Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IF, THEN problem...
#11
I dono, my friend just does that out of habit because he learned BASIC first at our school library from a book called "BASIC for Beginners." It was proper syntax in the book to do that. I just included it incase it had any relevence to the question. I somtimes use line numbers for GOTO, but then I only number the one line that I need to go back to.
-yah
Reply
#12
Zoasterboy,

In addition to the suggestions by others, I would modify your code as follows:
Code:
DO
    PRINT "Enter Y or N ";
    INPUT T$
    T$ = LCASE$(T$)   'Force lower case
LOOP WHILE LEFT$(T$,1) <> "y"
What I added:
1) Added a DO loop, so that the user can try again when he enters anything except "y",
Maybe if he entered some other character, you might want to do something else, or maybe terminate the program. I don't know.

2) Added the PRINT to tell user what to enter.

3) Did LCASE to force lower case since you are going to test for "y". The way it was, if the user pressed an upper case "Y", it wouldn't work.

4) Did LEFT$(T$,1) just in case user typed "yes". We are only interested in the first letter.

*****
Reply
#13
For God's sake, get rid of those line numbers Tongue

Welcome to the forums and good luck with your projects, btw.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#14
Quote:I dono, my friend just does that out of habit because he learned BASIC first at our school library from a book called "BASIC for Beginners."
My thought is that every book for learning Basic that includes line numbers should be burned on hell fire. :lookdown:
[Image: rg_link.png]
I'm a dog and I feel dirty baby
Reply
#15
Quote:
zoasterboy Wrote:When I try to run, it says "type mismatch" and highlights the "y" and the THEN

Code:
1 INPUT T
2 IF T = "y" THEN GOTO 3
3 END IF

Anyone have some help?

just a variable, by default, is an integer. "T" should be "T$"
the "$" makes is a string.
I know FB variables are, by default, integers, but doesn't QB use single precision floating point variables when the user leaves the type unspecified?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#16
Quote:I know FB variables are, by default, integers, but doesn't QB use single precision floating point variables when the user leaves the type unspecified?
You're exactly right. The default in QB is SINGLE.

*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)