我一直在Pascal編寫這個hang子手程序,我一直在看這個問題一段時間,並且無處可去。我原本以爲輸入內容也是\n
,但後來有點write()
,事實並非如此。當我輸入a
時,會發生什麼情況,它會經過循環並執行正確的操作,但隨後它會再次通過任何內容或新的行字符或不可見的內容。我試過確保guess
只能得到一個字符,但這使得它與無法看到的字符無數次循環。雖然循環執行一次(?)
如果任何人都可以提供任何關於哪裏出錯的信息,那就太棒了。谷歌其實不是一個非常大的幫助,一旦
無論如何,謝謝你可以提供的任何東西。
program p1;
const
MAX_GUESSES = 6;
mysteryWord = 'abomination';
//comparetext(str1,str2);
type
word = array[0 .. 11] of char;
var
guesses : word;
counter : integer;//for multipurpose counting ;)
wrong : integer;
keepGoing : boolean;
guess : char;
exists : boolean;
begin
guesses := '***********';
wrong := 0;
keepGoing := true;
repeat
keepGoing := false;
exists := false;
writeln('your word is ' + guesses + '.');
write('You have '); //this one line is separated into 3
write(6-wrong); //because it wont allow (6-wrong) to
writeln(' wrong guesses left!');//be put in line with strings.
write('Guess a letter: ');
read(guess);
for counter := 0 to 11 do
begin
if (guess = mysteryWord[counter]) then
begin
guesses[counter-1] := guess;
exists := true;
end;
end;
if(exists = false) then wrong := wrong + 1;
for counter := 0 to 11 do
begin
if(guesses[counter] = '*') then keepGoing := true;
end;
until ((wrong >= 6) or (keepGoing = false));
end.
「for counter:= 0 to 11 do」。字符串是「1」的。 –
這不會改變任何東西。 – roflcopter1101
好的。然後繼續訪問字符串的第0個和第-1個元素。 –