首页 > 用户发贴区 > 编程问题提问区 > 请大家帮忙,看看我错在哪?
2008
04-14

请大家帮忙,看看我错在哪?

#include<stdio.h>
#include<stdlib.h>
#include<time.h>


#define N 35
void  Choose1();
{
 int a[N]={1,2,3,4,5,6,
7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,
24,25,26,27,28,29,30,31,
32,33,34,35},i;
 int flag[N]={0},b[7];
 srand(time(NULL));
 for((int)i=0;i<7;i++)
 {
  int index=rand()%N;
  if(flag[index]==0)
  {
   b[i]=a[index];
   flag[index]=1;
  }
  else
   i–;
 }
 for(i=0;i<7;i++)
  printf(“%d “,b[i]);
 printf(“\n”);
 getchar();
}


#define P 30
Choose2();
{
 int a[P]={1,2,3,4,5,6,
7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,
24,25,26,27,28,29,30},i;
int flag[P]={0},b[7];
srand(time(NULL));
for((int)i=0;i<7;i++)
{
int index=rand()%P;
if(flag[index]==0)
{
b[i]=a[index];
flag[index]=1;
}
else
i–;
}
for(i=0;i<7;i++)
printf(“%d “,b[i]);
printf(“\n”);
getchar();
}


#define Q 25
Choose3();
{
 int a[Q]={1,2,3,4,5,6,
7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,
24,25},i;
int flag[Q]={0},b[7];
srand(time(NULL));
for((int)i=0;i<7;i++)
{
int index=rand()%Q;
if(flag[index]==0)
{
b[i]=a[index];
flag[index]=1;
}
else
i–;
}
for(i=0;i<7;i++)
printf(“%d “,b[i]);
printf(“\n”);
getchar();
}


#define W 18
Choose4();
{
 int a[W]={1,2,3,4,5,6,
7,8,9,10,11,12,13,14,15,
16,17,18},i;
int flag[W]={0},b[7];
srand(time(NULL));
for((int)i=0;i<7;i++)
{
int index=rand()%W;
if(flag[index]==0)
{
b[i]=a[index];
flag[index]=1;
}
else
i–;
}
for(i=0;i<7;i++)
printf(“%d “,b[i]);
printf(“\n”);
getchar();
}


#define Z 10
Choose5();
{
 int a[Z]={2,4,6,
8,10,12,14,
16,18,20},i;
int flag[Z]={0},b[10];
srand(time(NULL));
for((int)i=0;i<10;i++)
{
int index=rand()%Z;
if(flag[index]==0)
{
b[i]=a[index];
flag[index]=1;
}
else
i–;
}
for(i=0;i<7;i++)
printf(“%d “,b[i]);
printf(“\n”);
getchar();
}


Choose6();
{
       int i;
    printf(“产生 1 个3D号码:\n”);
       srand((unsigned)time(NULL));
    i= (printf(“%d “, rand() % 10));
    i= (printf(“%d “, rand() % 10));
    i= (printf(“%d “, rand() % 10));


}


void main()


 { 


  int select,N,P,Q,W,Z;
   
       do 
    {
     printf(” 0、退出\n”);
     printf(” 1、35选7\n”);
     printf(” 2、30选7\n”);
     printf(” 3、25选7\n”);
     printf(” 4、18选7\n”);
     printf(” 5、10选7\n”);
     printf(” 6、3D \n”);
     printf(“请选择功能:”);
     scanf(“%d”,&select);
     if(select == 0)
      break;
     switch(select)  {
     case 1 : Choose1(int);
      break;
        case 2 : Choose2();
      break;
        case 3 : Choose3();
      break;
        case 4 : Choose4();
      break;
        case 5 : Choose5();
      break;
        case 6 : Choose6();
      break;
        default :
      printf(“输入有误,请在 0~6 之间选择。\n”);


        }
     while(1);
    }
}


 


 


Configuration: 新建  – Win32 Debug——————–
Compiling…
新建 .c
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(7) : error C2449: found ‘{‘ at file scope (missing function header?)
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(30) : error C2059: syntax error : ‘}’
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(34) : error C2449: found ‘{‘ at file scope (missing function header?)
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(56) : error C2059: syntax error : ‘}’
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(60) : error C2449: found ‘{‘ at file scope (missing function header?)
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(82) : error C2059: syntax error : ‘}’
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(86) : error C2449: found ‘{‘ at file scope (missing function header?)
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(107) : error C2059: syntax error : ‘}’
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(111) : error C2449: found ‘{‘ at file scope (missing function header?)
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(132) : error C2059: syntax error : ‘}’
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(135) : error C2449: found ‘{‘ at file scope (missing function header?)
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\新建 .c(143) : error C2059: syntax error : ‘}’
Error executing cl.exe.


新建 .obj – 12 error(s), 0 warning(s)


请大家帮忙,看看我错在哪?》有 3 条评论

  1. 北极乞丐 说:

    大多数都是语法错误,先把基础部分看得差不多了再说

    比如

     switch(select)  {
         case 1 : Choose1(int);
          break;
            case 2 : Choose2();
          break;

    ///
    Choose1(int)这里能用int吗??

  2. michael 说:

    帮你看了一下

    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>

    #define N 35
    void  Choose1()
    {
     int a[N]={1,2,3,4,5,6,
    7,8,9,10,11,12,13,14,15,
    16,17,18,19,20,21,22,23,
    24,25,26,27,28,29,30,31,
    32,33,34,35},i;
     int flag[N]={0},b[7];
     srand(time(NULL));
     for((int)i=0;i<7;i++)
     {
      int index=rand()%N;
      if(flag[index]==0)
      {
       b[i]=a[index];
       flag[index]=1;
      }
      else
       i–;
     }
     for(i=0;i<7;i++)
      printf(“%d “,b[i]);
     printf(“\n”);
     getchar();
    }

    #define P 30
    Choose2()
    {
     int a[P]={1,2,3,4,5,6,
    7,8,9,10,11,12,13,14,15,
    16,17,18,19,20,21,22,23,
    24,25,26,27,28,29,30},i;
    int flag[P]={0},b[7];
    srand(time(NULL));
    for((int)i=0;i<7;i++)
    {
    int index=rand()%P;
    if(flag[index]==0)
    {
    b[i]=a[index];
    flag[index]=1;
    }
    else
    i–;
    }
    for(i=0;i<7;i++)
    printf(“%d “,b[i]);
    printf(“\n”);
    getchar();
    }

    #define Q 25
    Choose3()
    {
     int a[Q]={1,2,3,4,5,6,
    7,8,9,10,11,12,13,14,15,
    16,17,18,19,20,21,22,23,
    24,25},i;
    int flag[Q]={0},b[7];
    srand(time(NULL));
    for((int)i=0;i<7;i++)
    {
    int index=rand()%Q;
    if(flag[index]==0)
    {
    b[i]=a[index];
    flag[index]=1;
    }
    else
    i–;
    }
    for(i=0;i<7;i++)
    printf(“%d “,b[i]);
    printf(“\n”);
    getchar();
    }

    #define W 18
    Choose4()
    {
     int a[W]={1,2,3,4,5,6,
    7,8,9,10,11,12,13,14,15,
    16,17,18},i;
    int flag[W]={0},b[7];
    srand(time(NULL));
    for((int)i=0;i<7;i++)
    {
    int index=rand()%W;
    if(flag[index]==0)
    {
    b[i]=a[index];
    flag[index]=1;
    }
    else
    i–;
    }
    for(i=0;i<7;i++)
    printf(“%d “,b[i]);
    printf(“\n”);
    getchar();
    }

    #define Z 10
    Choose5()
    {
     int a[Z]={2,4,6,
    8,10,12,14,
    16,18,20},i;
    int flag[Z]={0},b[10];
    srand(time(NULL));
    for((int)i=0;i<10;i++)
    {
    int index=rand()%Z;
    if(flag[index]==0)
    {
    b[i]=a[index];
    flag[index]=1;
    }
    else
    i–;
    }
    for(i=0;i<7;i++)
    printf(“%d “,b[i]);
    printf(“\n”);
    getchar();
    }

    Choose6()
    {
           int i;
        printf(“产生 1 个3D号码:\n”);
           srand((unsigned)time(NULL));
        i= (printf(“%d “, rand() % 10));
        i= (printf(“%d “, rand() % 10));
        i= (printf(“%d “, rand() % 10));

    }

    void main()

     {
    int select;
     
          while(1)
            
        {
         printf(” 0、退出\n”);
         printf(” 1、35选7\n”);
         printf(” 2、30选7\n”);
         printf(” 3、25选7\n”);
         printf(” 4、18选7\n”);
         printf(” 5、10选7\n”);
         printf(” 6、3D \n”);
         printf(“请选择功能:”);
         scanf(“%d”,&select);
         if(select == 0)
          break;
         switch(select)  {
            case 1 : Choose1();
          break;
            case 2 : Choose2();
          break;
            case 3 : Choose3();
          break;
            case 4 : Choose4();
          break;
            case 5 : Choose5();
          break;
            case 6 : Choose6();
          break;
            default :
       printf(“输入有误,请在 0~6 之间选择。\n”);}

     }

        }
    你再试一下吧

    你好象定义函数的格式都弄错了

    应该是  函数名(){}    ()后面是没有;的

  3. 钟凯0716 说:

    谢谢大家的帮助!

留下一个回复