07.05.2015 Views

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

12. Using and Storing Data 87<br />

IF reply$ = answer$ THEN ! If correct...<br />

LET right = right + 1 ! Count correct replies<br />

PRINT “Correct.”<br />

! And say bravo<br />

ELSE<br />

PRINT “No, the correct answer is “; answer$; “.”<br />

PRINT #2: question$; ","; answer$<br />

END IF<br />

LOOP until end #1<br />

PRINT "All done. You answered"; right; "out of"; total;<br />

PRINT "questions correctly."<br />

CLOSE #1<br />

CLOSE #2<br />

END<br />

This program opens a second file and prints to it each missed question along with the correct<br />

response. Notice that the PRINT #2 statement also prints the comma that must separate<br />

these two items if you later wish to use the file for input.<br />

The CREATE NEWOLD keywords on the second OPEN statement tell <strong>True</strong> <strong>BASIC</strong> to create<br />

a new file if it can't find one with the specified name.<br />

The RESET #2: END statement tells <strong>True</strong> <strong>BASIC</strong> to move to the end of the second file. <strong>True</strong><br />

<strong>BASIC</strong> is always "looking" at the beginning of a newly opened file, which is fine if you are<br />

using the file for input or if the file is empty. But <strong>True</strong> <strong>BASIC</strong> can print only to the end of<br />

existing text files, so you must either erase the file or move to the end before you can PRINT.<br />

(If the file is empty, the RESET statement has no effect.)<br />

———————————————————————————————————————<br />

x If you want to PRINT to a text file that is not empty, you must first<br />

ERASE the file or RESET to the END of the file.<br />

———————————————————————————————————————<br />

Make these changes to the TRIVIA2 program and try it out.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!