|
Post by bouchad on Sept 25, 2022 16:55:23 GMT
Hello,
I am having issues with using OPEN command on a notepad file I have saved.
Here is the string:
PRINT "High/Low Game Program 4"
PRINT "Enter your name at the prompt"
INPUT Name$
Count=0
Answer$="Yes"
numbertoGuess=INT(RND(0)*10)+1
OPEN "NumberList1.txt"
DO WHILE Answer$="Yes"
Count=Count+1
PRINT
PRINT "A guess is input from the file"
INPUT#1, myGuess
PRINT "The guess is: "; myGuess
IF myGuess=numbertoGuess THEN
PRINT "Congratulations ";
PRINT Name$ ;
PRINT " you got it!"
PRINT "The number to be guessed is: ";numberToGuess
Answer$="No"
END IF
IF myGuess>numberToGuess THEN
PRINT "Your guess is too high process another guess"
END IF
IF MyGuess<numberToGuess THEN
PRINT "Your guess is too low process another guess"
END IF
LOOP
CLOSE#1
PRINT
PRINT "Game Over ";
PRINT Name$
PRINT "Your Score is: ";Count
I get a SYNTAX error on the OPEN "NumberList1.txt" line.
I have saved this Notepad file as where JustBasic is located, if that makes a difference.
This is what the NotePad file looks like:
1
2
3
4
5
6
7
8
9
10
eof
|
|
|
Post by tsh73 on Sept 25, 2022 17:49:28 GMT
Well, it's not
OPEN "NumberList1.txt" But
OPEN "NumberList1.txt" for input as #1
|
|
|
Post by plus on Sept 25, 2022 23:24:12 GMT
Yeah tsh73 just gave you syntax to open a file to read, but you read it line by line as input #1, aFileLine$ until you reach EOF(#1) = True From help: open "testfile" for input as #1 if eof(#1) < 0 then [skipIt] [loop] input #1, text$ print text$ if eof(#1) = 0 then [loop] [skipIt] close #1
Then to write to file, starting a whole new file: Open file$ for output as #1 print #1, aFileLine$ '... as much as you need close #1 'when done.
Don't know why you need to use files with the Hi/Lo Game???
|
|
|
Post by tsh73 on Sept 26, 2022 15:13:12 GMT
So it does work after change (just made a fiew runs).
|
|