| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6170 人关注过本帖
标题:求帮助,错误有关 error C2059: syntax error : 'type'
只看楼主 加入收藏
黑龙风月
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2014-6-6
结帖率:100%
收藏
 问题点数:0 回复次数:2 
求帮助,错误有关 error C2059: syntax error : 'type'
代码

#include<stdio.h>
#include<string.h>
#define N 30/*学生最多人数*/
#define M 10
#define COURSE_N 3/*考试科目数*/
#define MAX 20/*字符串最大长度*/
int ReadScore(int score[][COURSE_N],long num[],char name[][MAX]);/*录入学号,姓名和各科考试成绩*/
void AverageforCourse(int score[][COURSE_N],int sumC[],float averC[],int n);/*计算每门课程的总分和平均分*/
void AverageforStud(int score[][COURSE_N],int sumS[],float averS[],int n);/*计算每个学生的总分和平均分*/
void Print(int score[][COURSE_N],long num[],char name[][MAX],int n,int sumS[],float averS[],int sumC[],float averC[]);/*制表*/
void PerScore(int score[][COURSE_N],int n);/*百分比*/

void printscore(int score[][COURSE_N],long num[],int n,char name[][MAX]);/*打印学生学号,姓名和各科成绩*/
void SelectionSort(int score[][COURSE_N],int sumS[],long num[],char name[][MAX],int n,int (*compare)(int a,int b));/*通用的交换法排序*/
int Ascending(int a,int b);/*使数据按升序排序*/
int Descending(int a,int b);/*使数据按降序排序*/
void PrintfCourse(int sumC[],float averC[]);/*输出每门课程的总分和平均分*/
void PrintfStud(int sumS[],float averS[],long num[],char name[][MAX],int n);/*输出每个学生的总分和平均分*/
void NumScore(int score[][COURSE_N],int sumS[],long num[],int n,char name[][MAX]);/*按学号由小到大排出成绩表*/
int LinSearch(long num[],long x,int n);/*按学号查成绩*/

void SortString(int score[][COURSE_N],char name[][MAX],int n,int sumS[],long num[]);/*按字典顺序排序*/

int RandScore(int sumS[],int n,int h);/*按学号查询排名及成绩*/
int SearchbyName(char name[][MAX],int n,char na[N][MAX]);/*按姓名查询学生排名及其考试成绩*/
int main()
{
    int score[N][COURSE_N],n,sumS[N],sumC[N],pos,rand,h,k,j;
    float averS[N],averC[N];
    long num[N],x;
    char name[N][MAX],na[N][MAX];
    n=ReadScore(score,num,name);
   
    do{
    printf("\n******************************\n1.Append record\n2.Caculate total and average score of every course\n3.Caculate total and average score of every student\n4.Sort in descending order by total score of every student\n5.Sort in ascending order by total score of every student\n6.Sort in ascending order by number\n7.Sort in dictionary order by name\n8.Search by number\n9.Search by name\n10.Statistic analysis for every course\n11.List record\n0.exit\nPlease enter your choice:\n******************************\n\n");
    scanf("%d",&k);
    switch(k)
    {
    case 1:/*附加记录*/
        {
           n=ReadScore(score,num,name);
           printf("Total students are %d\n",n);
           break;
        }
    case 2:/*计算每门课程的总分和平均分*/
        {
            AverageforCourse(score,sumC,averC,n);
            PrintfCourse(sumC,averC);
            break;
        }
    case 3:/*计算每个学生的总分和平均分*/
        {
            AverageforStud(score,sumS,averS,n);
            PrintfStud(sumS,averS,num,name,n);
            break;
        }
    case 4:/*按每个学生的总分由高到低排出名次表*/
        {
          SelectionSort(score,sumS,num,name,n,Descending);
            printf("Data items in Descending order\n");
            printscore(score,num,n,name);
            break;  
        }
    case 5:/*按每个学生的总分由低到高排出名次表*/
        {
            SelectionSort(score,sumS,num,name,n,Ascending);
            printf("Data items in ascending order\n");
            printscore(score,num,n,name);
            break;
        }
    case 6:/*按学号由小到大排出成绩表*/
        {
             NumScore(score,sumS,num,n,name);
             printf("Sorted scores:\n");
             printscore(score,num,n,name);
             break;
        }
    case 7:/*按姓名的字典顺序排出成绩表*/
        {
            SortString(score,name,n,sumS,num);
            printf("Sorted results:\n");
                printscore(score,num,n,name);
        break;
        }
    case 8:/*按学号查询排名及成绩*/
        {
            printf("input the searching ID:");
            scanf("%ld",&x);
            pos=LinSearch(num,x,n);
            if(pos!=-1)
            {
               printf("%s's sumscore=%d\n",name[pos],sumS[pos]);
               h=sumS[pos];
               rand=RandScore(sumS,n,h);
               printf("the student's randing is:%d\n",rand);

            }
            else
            {
               printf("Not found!\n");
            }
            break;
        }
    case 9:/*按姓名查询学生排名及其考试成绩*/
        {
            
            j=SearchbyName(name,n,na);
         
            if(j!=-1)
            {
               printf("%s's sumscore=%d\n",name[j],sumS[j]);
               h=sumS[j];
               rand=RandScore(sumS,n,h);
               printf("the student's randing is:%d\n",rand);
            }
             else
            {
               printf("Not found!\n");
            }
            break;
        }
    case 10:/*统计每个类别的人数以及所占的百分比*/
        {
           PerScore(score,n);
           
           break;
        }      
    case 11:/*列表*/
        {
        Print(score,num,name,n,sumS,averS,sumC,averC);
         break;
        }

    }
    }while(k>0&&k<=M);
   
    return 0;
}





/*计算每个学生的总分和平均分*/
void AverageforStud(int score[][COURSE_N],int sumS[],float averS[],int n)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        sumS[i]=0;
            for(j=0;j<COURSE_N;j++)
            {
                sumS[i]=sumS[i]+score[i][j];
            }
            averS[i]=(float)sumS[i]/COURSE_N;
    }
}



/*计算每门课程的总分和平均分*/
void AverageforCourse(int score[][COURSE_N],int sumC[],float averC[],int n)
{
    int i,j;
    for(j=0;j<COURSE_N;j++)
    {
        sumC[j]=0;
        for(i=0;i<n;i++)
        {
        sumC[j]=sumC[j]+score[i][j];
        }
    }
   averC[j]=(float)sumC[j]/n;
}





/*录入学号,姓名和各科考试成绩*/
int ReadScore(int score[][COURSE_N],long num[],char name[][MAX])
{
    static int i;
    int j,n;
    i=i-1;
    do{
         i++;
         printf("input the total number of the students(n<30):");
         scanf("%d",&n);
         printf("Input student's ID,name and score as:MT EN PH:\n");
         for(i=0;i<n;i++)
         {scanf("%ld",&num[i]);
         getchar();
         scanf("%s",name[i]);
         for(j=0;j<COURSE_N;j++)
         {
         scanf("%d",&score[i][j]);
         }
     }while(num[i]>0&&score[i][j]>=0);
     return i;
}



/*打印学生学号,姓名和各科成绩*/
void printscore(int score[][COURSE_N],long num[],int n,char name[][MAX])/*error C2059: syntax error : 'type'*/

{
    int i,j;
    for(i=0;i<n;i++)
    {
        printf("% 12ld\t % 8s\t",num[i],name[i]);
       for(j=0;j<COURSE_N;j++)
       {
        printf("% 4d\t",score[i][j]);
       }
    }
}



/*按学号由小到大排出成绩表*/
void NumScore(int score[][COURSE_N],int sumS[],long num[],int n,char name[][MAX])
{
    int i,j,k,m,temp1,temp4[N][COURSE_N];
    long temp2;
    char temp3[MAX];
    for(i=0;i<n-1;i++)
    {  
        for(m=0;m<COURSE_N;m++)
        {

        k=i;
        for(j=i+1;j<n;j++)
        {
            if(num[j]<num[k])
            {
                k=j;
            }
        }
        if(k!=i)
            {
               temp1=num[k];
              num[k]=num[i];
               num[i]=temp1;
               temp2=sumS[k];
               sumS[k]=sumS[i];
               sumS[i]=temp2;
               strcpy(temp3,name[k]);
              strcpy(name[k],name[i]);
              strcpy(name[i],temp3);
              temp4[k][m]=score[k][m];
              score[k][m]=score[i][m];
              score[i][m]=temp4[k][m];
             }
        }
    }
}




/*查成绩*/
int LinSearch(long num[],long x,int n)
{
     int i;
     for(i=0;i<n;i++)
     {
         if(num[i]==x)
             return(i);/*若找到则返回x在数组中的下标*/
     }
     return -1;/*若循环结束仍未找到,则返回-1*/
}
/*名次*/
int RandScore(int sumS[],int n,int h)
{
    int i,j=1;
    for(i=0;i<=n;i++)
    {
        if(h<sumS[i])
        {
            j++;
        }
    }
    return j;
}
/*百分比*/
void PerScore(int score[][COURSE_N],int n)
{
    int i,j,a=0,b=0,c=0,d=0,e=0;
    float f1,f2,f3,f4,f5;
    printf("MT EN PH三科成绩统计分别为:\n");

    for(i=0;i<n;i++)
    {
    for(j=0;j<COURSE_N;j++)
    {
        if(score[i][j]>=90&&score[i][j]<=100)
        {
            a++;
        }
        else if(score[i][j]>=80&&score[i][j]<=89)
        {
            b++;
        }
        else if(score[i][j]>=70&&score[i][j]<=79)
        {
            c++;
        }
        else if(score[i][j]>=60&&score[i][j]<=69)
        {
            d++;
        }
        else
        {
            e++;
        }
    }
    f1=(float)a/n*100;
    f2=(float)b/n*100;
    f3=(float)c/n*100;
    f4=(float)d/n*100;
    f5=(float)e/n*100;
    printf("优秀%d人,占%%%f;良好%d人,占%%%f;中等%d人,占%%%f;及格%d人,占%%%f;不及格%d人,占%%%f\n",a,f1,b,f2,c,f3,d,f4,e,f5);
    }
}
/*制表*/
void Print(int score[][COURSE_N],long num[],char name[][MAX],int n,int sumS[],float averS[],int sumC[],float averC[])
{
    int i,j;
    printf("Counting Result:\n");
    printf("Student's ID\t name\t\t EN \t PH \t SUM \t AVER \n");
    for(i=0;i<n;i++)
    {
        printf("% 12ld\t % 8s\t",num[i],name[i]);
       for(j=0;j<COURSE_N;j++)
       {
        printf("% 4d\t",score[i][j]);
       }
    printf("% 4d\t% 5.1f\n",sumS[i],averS[i]);
    }
    printf("SumofCourse \t");
    for(j=0;j<COURSE_N;j++)
    {
        printf("% 4d\t",sumC[j]);
    }
    printf("AverofCourse \t");
    for(j=0;j<COURSE_N;j++)
    {
    printf("% 4.1f\t",averC[j]);
    }
    printf("\n");
}
/*通用的交换法排序*/
void SelectionSort(int score[][COURSE_N],int sumS[],long num[],char name[][MAX],int n,int (*compare)(int a,int b))
{
    int i,j,k,m,temp1,temp4[N][COURSE_N];
    long temp2;
    char temp[MAX];
    for(i=0;i<n-1;i++)
    {  
        for(m=0;m<COURSE_N;m++)
        {
        k=i;
        for(j=i+1;j<n;j++)
        {
        {
            if((*compare)(sumS[j],sumS[k]))
            {
                k=j;
            }
        }
        if(k!=i)
            {
               temp1=sumS[k];
               sumS[k]=sumS[i];
               sumS[i]=temp1;
               temp2=num[k];
               num[k]=num[i];
               num[i]=temp2;
              strcpy(temp,name[k]);
              strcpy(name[k],name[i]);
              strcpy(name[i],temp);
              temp4[k][m]=score[k][m];
              score[k][m]=score[i][m];
              score[i][m]=temp4[k][m];
             }
        }
        }
    }
}
/*使数据按升序排序*/
int Ascending(int a,int b)
{
    return a<b;
}
/*使数据按降序排序*/
int Descending(int a,int b)
{
    return a>b;
}

/*按字典顺序排序*/
void SortString(int score[][COURSE_N],char name[][MAX],int n,int sumS[],long num[])
{
    int i,j,m,temp1,temp4[N][COURSE_N];
    long temp2;
    char temp[MAX];
    for(i=0;i<n-1;i++)
    {
        for(m=0;m<COURSE_N;m++)
        {
        for(j=i+1;j<n;j++)
        {
        if(strcmp(name[j],name[i])<0)
        {
            strcpy(temp,name[i]);
            strcpy(name[i],name[j]);
            strcpy(name[j],temp);
            temp1=sumS[i];
               sumS[i]=sumS[j];
               sumS[j]=temp1;
               temp2=num[i];
               num[i]=num[j];
               num[j]=temp2;
               temp4[i][m]=score[i][m];
              score[i][m]=score[j][m];
              score[j][m]=temp4[i][m];
        }
        }
        }
    }
}

/*按姓名查询学生排名及其考试成绩*/
int SearchbyName(char name[][MAX],int n,char na[N][MAX])
{
    int i,j=0;
    printf("input the searching name:");
              scanf("%s",na[j]);
    for(i=0;i<n;i++)
    {
    if(strcmp(na[j],name[i])==0)
        {
            return(i);
        }
    }
    return -1;
}

/*输出每门课程的总分和平均分*/
void PrintfCourse(int sumC[],float averC[])
{
    int i,j;
    printf("Course\t MT \t EN \t PH \n");
    printf("SumofCourse \t");
    for(j=0;j<COURSE_N;j++)
    {
        printf("% 4d\t",sumC[j]);
    }
    printf("AverofCourse \t");
    for(j=0;j<COURSE_N;j++)
    {
    printf("% 4.1f\t",averC[j]);
    }
    printf("\n");
}

/*输出每个学生的总分和平均分*/
void PrintfStud(int sumS[],float averS[],long num[],char name[][MAX],int n)
{
    int i,j;
    printf("Student's ID\t name \t Sum \t Aver \n");
    for(i=0;i<n;i++)
    {
        printf("% 12ld\t % 8s\t",num[i],name[i]);
        printf("% 4d\t% 5.1f\n",sumS[i],averS[i]);
    }
}


不知道到底哪里错了
搜索更多相关主题的帖子: 考试成绩 include 考试科目 字符串 
2014-06-06 21:21
黑龙风月
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2014-6-6
收藏
得分:0 
/*打印学生学号,姓名和各科成绩*/
void printscore(int score[][COURSE_N],long num[],int n,char name[][MAX])/*error C2059: syntax error : 'type'*/

{
    int i,j;
    for(i=0;i<n;i++)
    {
        printf("% 12ld\t % 8s\t",num[i],name[i]);
       for(j=0;j<COURSE_N;j++)
       {
        printf("% 4d\t",score[i][j]);
       }
    }
}
2014-06-06 21:41
黑龙风月
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2014-6-6
收藏
得分:0 
为什么没有人呢?
2014-06-07 09:38
快速回复:求帮助,错误有关 error C2059: syntax error : 'type'
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033657 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved