Re: Interrupting & later completing a program
- Posted by irv mullins <irvm at ellijay.com> Jul 13, 2004
- 622 views
Alex Caracatsanis wrote: > The exact algorithm isn't important here. Let's say the user answers 3 > questions, quits, > then returns tomorrow to complete the remaining questions and get the answer. > How would > I code a DOS program to achieve that? I'm guessing I'll need to write the > answers to > a data file to be opened for update later. How would the program "know" where > the user > left off last time, so that it could continue from that point later on? Alex: Think first about how you're going to store the answers. Perhaps a simple sequence, using 0 for 'no' and 1 for 'yes'. If the user had answered 3 questions, your sequence would look like: {1,0,1} Write that to disk. Your question-asking routine could be a function which would take a single parameter (which_question) and display that question, returning a '1' or '0' depending upon what the user replied. (Perhaps -1 if the user wants to quit) Read in the saved sequence from disk, look at the length (3 in this case), and then start up again from there. If s is the sequence read from disk:
integer ans for x = length(s)+1 to MAX_QUESTIONS do ans = ask(x) if ans = -1 then print(fn,s) exit else s &= ans end if end for
Regards, Irv