我一直在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个元素。 –