我在Turbo C中做了一个简单的程序,它像一个猜谜游戏。它应该在用户输入3个错误字符后或者在正确的字符被猜出后立即结束游戏。然而,它不工作,我不明白为什么。输入4个字符(错误或不正确)后,游戏关闭。turbo c猜谜游戏do/while循环
#include <stdio.h>
#include <conio.h>
void main(void)
{
char ch;
int tries = 0;
int win_flag = 0;
clrscr();
printf("Guess the letter: ");
do
{
ch = getch();
printf("%c", ch);
tries++;
if (ch == 'a')
win_flag = 1;
else
win_flag = 0;
}
while (tries <= 3 || win_flag == 1);
if (tries <= 3)
printf("\nGame over.");
else if (win_flag == 1)
printf("\nYou win!");
getch();
}
谢谢,就是这样。 – user3359196