这是一个关于剪子包袱锤头游戏的小程序
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h>
void main() 
{ int a=0,b=0;//a随机数,b用户输入
  char f=' ';//是否继续游戏
  char c[3]={"剪子","包袱","锤"};
while(1)
  {
while(1)
       {
       a=rand()%3+1;//生成1~3随机数
       printf("猜拳游戏开始。\n1.%s\n2.%s\n3.%s\n",c[1],c[2],c[3]);
       scanf("%d",&b);
       fflush(stdin);
       if ((b>=1)&&(b<=3))//验证输入数字是否正确
          {break;}
       else
          {printf("输入错误请重新输入。\n");}
        }
     printf("(计算机)%s:(用户)%s\n",c[a-1],a[b-1]);
       if (a==1)//剪子
           {
            switch(b)
               {case 1:printf("平局,>_<\n");break;
                case 2:printf("输了,@_@\n");break;
                case 3:printf("胜利!^_^\n");break;
               }
   }
   else if (a==2)//包袱
         {
         switch(b)
               {
                case 1:printf("胜利!^_^\n");break;
                case 2:printf("平局,>_<");break;
                case 3:printf("输了,@_@\n\n");break;
               }
   else if(a==3)//锤
         {
           switch(b)
               {case 1:printf("输了,@_@\n");break;
                case 2:printf("胜利!^_^\n");break;
                case 3:printf("平局,>_<\n");break;
               }
   printf("是否继续游戏?(y/n)");
   scanf("%c",f);
   if((f!=y)||(f!=Y))
       break;
   }
}
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Documents and Settings\Administrator\My Documents\作业\测试\正在测试项目\Cpp1.cpp(7) : error C2117: '剪子' : array bounds overflow
C:\Documents and Settings\Administrator\My Documents\作业\测试\正在测试项目\Cpp1.cpp(7) : error C2117: '包袱' : array bounds overflow
C:\Documents and Settings\Administrator\My Documents\作业\测试\正在测试项目\Cpp1.cpp(7) : error C2078: too many initializers
C:\Documents and Settings\Administrator\My Documents\作业\测试\正在测试项目\Cpp1.cpp(21) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Administrator\My Documents\作业\测试\正在测试项目\Cpp1.cpp(35) : error C2181: illegal else without matching if
C:\Documents and Settings\Administrator\My Documents\作业\测试\正在测试项目\Cpp1.cpp(43) : error C2065: 'y' : undeclared identifier
C:\Documents and Settings\Administrator\My Documents\作业\测试\正在测试项目\Cpp1.cpp(43) : error C2065: 'Y' : undeclared identifier
C:\Documents and Settings\Administrator\My Documents\作业\测试\正在测试项目\Cpp1.cpp(47) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
Cpp1.obj - 1 error(s), 0 warning(s)
我的英文水平不好 请问那里的错误哦?、、、、?
此程序能否简洁一些呢?~~ 谢谢
[此贴子已经被作者于2007-3-20 19:52:34编辑过]

 
											





 
	     
											




