本帖最後由 沙奈朵‧路比 於 12/6/2012 11:21 PM 編輯 我不知你這program在procedure你輸入的guess是否完整,所以有點地方我說不對,可能嘟在其他地方有補正也說不定。 問題應該是repeat/until身上。 首先你頭一個if是想讓人repeat估answer直到guess=answer,再細看,除了guess > answer 和guess < answer之外,你還有guess = answer要處理。而你第二個if是想當發生guess不在合理的範時,讓人repeat輸入guess直到(guess<max) and (guess>min)。所以兩者要until的條件不同,放在同一個repeat是不合理的。 以你目前的repeat,當你輸入一次guess之後,若在範圍內,你會得到 max = guess 或 min = guess,由於在範圍內,你run完一次後就會完成repeat。 我想第二次個if基本沒錯,只是我不懂甚麼是delay而已== 話說我這樣做
Randomize; random_num:= Random(random(max-min))+min; rec := 0; win := TRUE; Repeat rec := rec+1; write('Input a number: ');readln(num); if (num>max) or (num<min) thenrepeat writeln('*****************************************************************'); writeln('The input number ',num,' is not in the range of',min, ' - ', max); writeln('Please input another number: ');readln(num); until (num<max) and (num>min); if num < random_num then begin writeln('*****************************************************************'); writeln('Incorrect! The number is too small.'); min := num; writeln('The range is ',min,' - ', max); writeln('You have inputted ',rec,' time'); writeln('Please try again'); end else if num > random_num then begin writeln('************************************************************'); writeln('Incorrect! The number is too large.'); max := num; writeln('The range is ',min, ' - ', max); writeln('You have inputted ',rec,' time'); writeln('Please try again'); end else begin writeln('******************************************************'); writeln('You are correct! The answer is ',random_num); writeln('You have inputted ',rec,' time'); win := FALSE; end; if win then begin com := random(random(max-min))+min+1; writeln('**********************************************************'); writeln('The number computer guests is ',com); if com < random_num then begin min := com; writeln('The range is ',min,' - ', max); end else if com > random_num then begin writeln('****************************************************'); max := com; writeln('The range is ',min, ' - ', max); end else begin writeln('********************************************************'); writeln('The computer is correct! The answer is ',random_num); writeln('You are lose!!!'); end end until (num = random_num) or (com = random_num) end 也許我說的不是嘟想帶出的問題,如果是error的話,不如嘟把錯的那句特別quote出來看看。 |