求哪位大神试英文猜单词程序。拜托了,急求。最好能在两天内完成,真的非常感谢,拜托了。谢谢!!!

2025-12-06 15:28:21
推荐回答(1个)
回答1:

试一下以下代码

#include
#include

void main()
{
char *p;
int i,count=10,rightcount=0; //
char answer[]="junk";
char guess, userguess[100];

for (i=0;i<(int)strlen(answer);i++)
userguess[i]='-';

while( rightcount < strlen(answer) && count!=0 )
{
printf("The word now looks like this :%s\n",userguess);

if(count!=1)
printf("You have %d guesses left.\n",count);
else
printf("You have only one guess left.\n");
printf("Your guess:");
scanf("%c%*c",&guess); //去除回车确认符

if(p=strchr(answer,guess))
{
*(userguess+(p-answer))=*p;
rightcount++;
*p='-';
printf("The guess is correct.\n");
}
else
{
count--;
printf("There are no %c's in the word.\n\a",guess);
}
}
if( rightcount==strlen(answer) )
printf("You win.\n");
else
printf("You lose.\n");
}