我正在学习基础编程作为我高中的课程。在学校开始编程之前,我已经学习了一些 C++。我正在编写一个用于或文件的TELEPHONE DIRECTORY
程序。WRITES
READS FROM
"Records.dat"
当我运行程序并进入"Q"
退出时,它工作正常。但是,如果我 Enter"E"
以输入新记录APPEND MODE
或"O"
以OUTPUT
模式输入记录或"V"
查看记录,则程序不会执行任何操作。它会创建文件并且不会挂起,但不会显示任何输出。这是代码:
10 CLS
20 Name$ = "0": Number$ = "0": Adrs$ = "0": Choice$ = "0": Mode$ = "0": Records = 0: Space = 0
30 PRINT "Telephone Directory Program."; "Press 'E' to Enter new records in Existing File"; "Press 'V' to View existing records"; "Press 'Q' to Exit"; "IF THERE ARE NO RECORDS PRESS O";
40 INPUT Mode$
50 IF Mode$ = "Q" THEN
END
ELSEIF Mode$ = "E" THEN
CLS
OPEN "Records.dat" FOR APPEND AS #1
ON ERROR GOTO 30
PRINT "Enter Records when prompted.";
WHILE Choice$ = "Y" OR Choice$ = "y"
INPUT "Enter Name: ", Name$
INPUT "Enter Phone Number: ", Number$
INPUT "Enter Address: ", Adrs$
WRITE #1, Name$, Number$, Adrs$
INPUT "IF you want to enter new records, enter Y or y. Otherwise, press any other letter. ", Choice$
WEND
CLOSE #1
GOTO 10
ELSEIF Mode$ = "O" THEN
CLS
OPEN "Records.dat" FOR OUTPUT AS #2
PRINT "Enter Records when prompted.";
WHILE Choice$ = "Y" OR Choice$ = "y"
INPUT "Enter Name: ", Name$
INPUT "Enter Phone Number: ", Number$
INPUT "Enter Address: ", Adrs$
WRITE #1, Name$, Number$, Adrs$
INPUT "IF you want to enter new records, enter Y or y. Otherwise, press any other letter. ", Choice$
WEND
CLOSE #2
GOTO 10
ELSEIF Mode$ = "V" THEN
CLS
OPEN "Records.dat" FOR INPUT AS #3
PRINT SPC(24), "Directory Listing";
WHILE NOT EOF(3)
Records = Records + 1
WEND
IF Records = 0 THEN
PRINT "NO RECORDS FOUND. ENTER O AT THE NEXT SCREEN";
GOTO 10
ELSE
PRINT "Names", SPC(5), "Phone Numbers ", SPC(6), "Addresses";
WHILE NOT EOF(3)
INPUT #3, Name$, Number$, Adrs$
PRINT Name$
Space = (10 - (LEN(Name$)))
PRINT SPC(Space)
PRINT Number$
Space = (20 - (LEN(Number$)))
PRINT SPC(Space)
PRINT Adrs$;
WEND
PRINT ;
PRINT Records, " Records found";
CLOSE #3
GOTO 10
END IF
END IF