香港寵物小精靈村落 論壇

 找回密碼
 加入
查看: 4338|回復: 2
打印 上一主題 下一主題

[求助] ict programming 有問題...

[複製鏈接]
跳轉到指定樓層
1#
發表於 2/6/2012 09:47 PM | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 傻嘟哥 於 2/6/2012 11:21 PM 編輯

我係用pascal寫的
是關於開口中估數字的那一part...
              Repeat
              readln (guess);
                if (guess<max) and (guess>min) then
                  begin
                    if guess>answer then
                      max:=guess;
                    if guess<answer then
                      min:=guess;
                  end;
                if (guess>max) or (guess<min) then
                  begin
                    ClrScr;
                    Writeln ('[Get It At Once]');
                    Delay(1000);
                    Writeln ('Please mind the range!(',min, '-',max,')');
                    Delay(1000);
                    Writeln ('Input another number please~');
                  end;
              Until (guess<max) and (guess>min);

我想set就係玩家打個數字超出「當時」個range個陣 會叫玩家再打過
但係唔知邊度出了錯呢...
2#
發表於 12/6/2012 11:16 PM | 只看該作者
本帖最後由 沙奈朵‧路比 於 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出來看看。
回復

使用道具 舉報

3#
發表於 13/6/2012 12:20 AM | 只看該作者
本帖最後由 fortexe2 於 13/6/2012 12:27 AM 編輯

Delay(1000)  應該=倒數1000ms
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 加入

本版積分規則

手機版|Archiver|香港寵物小精靈村落

GMT+8, 23/10/2024 04:28 PM , Processed in 0.012133 second(s), 14 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表