猜词游戏ISU

Submitted by Dot on Fri, 09/05/2008 - 21:00

/*还有几个问题有待解决。循环还是有问题。另外,如果需要扩展用户自定义单词、单词隐藏位以及程序提示信息的功能的话,还要提供将用户输入写入程序的接口。*/


#include
#include
#define NO 0
#define YES 1
char capital(char x);
void main()
{
char ch,word[]={" SUSSESS"};
int i,times,done=NO;
/*这个循环用来输出单词,但不显示指定的字母。其中调用函数strlen()来判断单词的位数*/
for (i=1;i<=strlen(word);i++)
(i==2)?putchar('?'):printf("%c",word);
for (times=0;done==NO;times++)
{
printf("\n");
puts("Eneter a character.");
scanf("%c",&ch);
if(capital(ch)==word[2]) done=YES;
else puts("wrong!Try again.");
}
printf("%s\nWell done!\n",word);
printf("You guessed %d times.\n",times);
system("pause");
}
char capital(char x)
{
char y;
if((x<=90)&&(x>=65)) {y=x;putchar(x);}
else if((x<=122)&&(x>=97)) {y=x-32;putchar(x);}
else puts("Please enter a character!");
return(y);
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.