VC6,C语言,一段小程序,请帮忙改个语法
#include<stdio.h>typedefstructstudent{intnum;charname[20];floatscore[3];}student;stud...
#include<stdio.h>
typedef struct student
{
int num;
char name[20];
float score[3];
}student;
student stu[4];
void main()
{
float average[4],max;
int i;int k=0;int j=0;
printf("Please input the information:\n");
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[0].num,&stu[0].name,&stu[0].score[0],&stu[0].score[1],&stu[0].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[1].num,&stu[1].name,&stu[1].score[0],&stu[1].score[1],&stu[1].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[2].num,&stu[2].name,&stu[2].score[0],&stu[2].score[1],&stu[2].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[3].num,&stu[3].name,&stu[3].score[0],&stu[3].score[1],&stu[3].score[2]);
for(i=0;i<4;i++)
average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
for(i=0;i<4;i++)
printf("the score average of the student %d is:%f"stu[i].num,average[i]);
for(i=0;i<4;i++)
{
max=average[k];
j++;
if(max<average[j])
{
max=average[j];
k=j;
}
}
printf("the information of the best student is:\n %d %c %f %f %f %f",stu[j].num,stu[j].name,stu[j].score[0],stu[j].score[1],stu[j].score[2],average[j]);
}
--------------------Configuration: 链表练习 - Win32 Debug--------------------
Compiling...
01.cpp
D:\VC6.0++\MSDev98\MyProjects\链表练习\01.cpp(21) : error C2146: syntax error : missing ')' before identifier 'stu'
D:\VC6.0++\MSDev98\MyProjects\链表练习\01.cpp(21) : error C2059: syntax error : ')'
执行 cl.exe 时出错.
01.obj - 1 error(s), 0 warning(s) 展开
typedef struct student
{
int num;
char name[20];
float score[3];
}student;
student stu[4];
void main()
{
float average[4],max;
int i;int k=0;int j=0;
printf("Please input the information:\n");
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[0].num,&stu[0].name,&stu[0].score[0],&stu[0].score[1],&stu[0].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[1].num,&stu[1].name,&stu[1].score[0],&stu[1].score[1],&stu[1].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[2].num,&stu[2].name,&stu[2].score[0],&stu[2].score[1],&stu[2].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[3].num,&stu[3].name,&stu[3].score[0],&stu[3].score[1],&stu[3].score[2]);
for(i=0;i<4;i++)
average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
for(i=0;i<4;i++)
printf("the score average of the student %d is:%f"stu[i].num,average[i]);
for(i=0;i<4;i++)
{
max=average[k];
j++;
if(max<average[j])
{
max=average[j];
k=j;
}
}
printf("the information of the best student is:\n %d %c %f %f %f %f",stu[j].num,stu[j].name,stu[j].score[0],stu[j].score[1],stu[j].score[2],average[j]);
}
--------------------Configuration: 链表练习 - Win32 Debug--------------------
Compiling...
01.cpp
D:\VC6.0++\MSDev98\MyProjects\链表练习\01.cpp(21) : error C2146: syntax error : missing ')' before identifier 'stu'
D:\VC6.0++\MSDev98\MyProjects\链表练习\01.cpp(21) : error C2059: syntax error : ')'
执行 cl.exe 时出错.
01.obj - 1 error(s), 0 warning(s) 展开
3个回答
展开全部
#include<stdio.h>
typedef struct student
{
int num;
char name[20];
float score[3];
}student;
student stu[4];
void main()
{
float average[4],max;
int i;int k=0;int j=0;
printf("Please input the information:\n");
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[0].num,&stu[0].name,&stu[0].score[0],&stu[0].score[1],&stu[0].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[1].num,&stu[1].name,&stu[1].score[0],&stu[1].score[1],&stu[1].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[2].num,&stu[2].name,&stu[2].score[0],&stu[2].score[1],&stu[2].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[3].num,&stu[3].name,&stu[3].score[0],&stu[3].score[1],&stu[3].score[2]);
for(i=0;i<4;i++)
average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
for(i=0;i<4;i++)
printf("the score average of the student %d is:%f",stu[i].num,average[i]); //逗号 双一号后面少了个逗号
for(i=0;i<4;i++)
{
max=average[k];
j++;
if(max<average[j])
{
max=average[j];
k=j;
}
}
printf("the information of the best student is:\n %d %c %f %f %f %f",stu[j].num,stu[j].name,stu[j].score[0],stu[j].score[1],stu[j].score[2],average[j]);
}
typedef struct student
{
int num;
char name[20];
float score[3];
}student;
student stu[4];
void main()
{
float average[4],max;
int i;int k=0;int j=0;
printf("Please input the information:\n");
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[0].num,&stu[0].name,&stu[0].score[0],&stu[0].score[1],&stu[0].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[1].num,&stu[1].name,&stu[1].score[0],&stu[1].score[1],&stu[1].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[2].num,&stu[2].name,&stu[2].score[0],&stu[2].score[1],&stu[2].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[3].num,&stu[3].name,&stu[3].score[0],&stu[3].score[1],&stu[3].score[2]);
for(i=0;i<4;i++)
average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
for(i=0;i<4;i++)
printf("the score average of the student %d is:%f",stu[i].num,average[i]); //逗号 双一号后面少了个逗号
for(i=0;i<4;i++)
{
max=average[k];
j++;
if(max<average[j])
{
max=average[j];
k=j;
}
}
printf("the information of the best student is:\n %d %c %f %f %f %f",stu[j].num,stu[j].name,stu[j].score[0],stu[j].score[1],stu[j].score[2],average[j]);
}
更多追问追答
追问
我想问为什么算平均分average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
结果都是没算对的?例如是95 94 92得到的结果却是62.000000?要怎么改数值类型?
追答
你的错误还很多
scanf 的输入格式你完全不会啊?
而且 name是char数组 你输入时却设置接收一个char
还有scanf格式里的那么多的双引号
而且scanf格式里的\n你是无法输入的
scanf("%d %s %f %f %f ",&stu[0].num,&stu[0].name,&stu[0].score[0],&stu[0].score[1],&stu[0].score[2]);
记录最大平均分也不对
下面是我把错误全改过的
Please input the information:
111 aaa 76 88 65
222 bbb 98 78 54
333 ccc 76 89 55
444 ddd 87 99 66
the score average of the student 111 is:51.000000
the score average of the student 222 is:44.000000
the score average of the student 333 is:48.000000
the score average of the student 444 is:55.000000
the information of the best student is:
444 ddd 87.000000 99.000000 66.000000 55.000000
Press any key to continue
#include
typedef struct student
{
int num;
char name[20];
float score[3];
}student;
student stu[4];
void main()
{
float average[4],max;
int i;int k=0;int j=0;
printf("Please input the information:\n");
scanf("%d %s %f %f %f",&stu[0].num,&stu[0].name,&stu[0].score[0],&stu[0].score[1],&stu[0].score[2]);
scanf("%d %s %f %f %f",&stu[1].num,&stu[1].name,&stu[1].score[0],&stu[1].score[1],&stu[1].score[2]);
scanf("%d %s %f %f %f",&stu[2].num,&stu[2].name,&stu[2].score[0],&stu[2].score[1],&stu[2].score[2]);
scanf("%d %s %f %f %f",&stu[3].num,&stu[3].name,&stu[3].score[0],&stu[3].score[1],&stu[3].score[2]);
for(i=0;i<4;i++)
average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
for(i=0;i<4;i++)
printf("the score average of the student %d is:%f\n",stu[i].num,average[i]); //逗号 双一号后面少了个逗号
for(i=0;i<4;i++)
{
if(i==0 ||max<average[i])
{
max=average[i];
j=i;
}
}
printf("the information of the best student is:\n %d %s %f %f %f %f\n",stu[j].num,stu[j].name,stu[j].score[0],stu[j].score[1],stu[j].score[2],average[j]);
}
展开全部
// test333.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
typedef struct student
{
int num;
char name[20];
float score[3];
}student;
student stu[4];
void main()
{
float average[4],max;
int i;int k=0;int j=0;
printf("Please input the information:\n");
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[0].num,&stu[0].name,&stu[0].score[0],&stu[0].score[1],&stu[0].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[1].num,&stu[1].name,&stu[1].score[0],&stu[1].score[1],&stu[1].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[2].num,&stu[2].name,&stu[2].score[0],&stu[2].score[1],&stu[2].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[3].num,&stu[3].name,&stu[3].score[0],&stu[3].score[1],&stu[3].score[2]);
for(i=0;i<4;i++)
average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
for(i=0;i<4;i++)
printf("the score average of the student %d is:%f",stu[i].num,average[i]);
for(i=0;i<4;i++)
{
max=average[k];
j++;
if(max<average[j])
{
max=average[j];
k=j;
}
}
printf("the information of the best student is:\n %d %c %f %f %f %f",stu[j].num,stu[j].name,stu[j].score[0],stu[j].score[1],stu[j].score[2],average[j]);
}
//
#include "stdafx.h"
#include<stdio.h>
typedef struct student
{
int num;
char name[20];
float score[3];
}student;
student stu[4];
void main()
{
float average[4],max;
int i;int k=0;int j=0;
printf("Please input the information:\n");
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[0].num,&stu[0].name,&stu[0].score[0],&stu[0].score[1],&stu[0].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[1].num,&stu[1].name,&stu[1].score[0],&stu[1].score[1],&stu[1].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[2].num,&stu[2].name,&stu[2].score[0],&stu[2].score[1],&stu[2].score[2]);
scanf("%d ""%c ""%f ""%f ""%f \n",&stu[3].num,&stu[3].name,&stu[3].score[0],&stu[3].score[1],&stu[3].score[2]);
for(i=0;i<4;i++)
average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
for(i=0;i<4;i++)
printf("the score average of the student %d is:%f",stu[i].num,average[i]);
for(i=0;i<4;i++)
{
max=average[k];
j++;
if(max<average[j])
{
max=average[j];
k=j;
}
}
printf("the information of the best student is:\n %d %c %f %f %f %f",stu[j].num,stu[j].name,stu[j].score[0],stu[j].score[1],stu[j].score[2],average[j]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
scanf("%d %c %f %f %f \n",&stu[3].num,&stu[3].name,&stu[3].score[0],&stu[3].score[1],&stu[3].score[2]);
for(i=0;i<4;i++)
{
average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
printf("the score average of the student %d is:%f"stu[i].num,average[i]);
}
这样应该可以了
for(i=0;i<4;i++)
{
average[i]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3;
printf("the score average of the student %d is:%f"stu[i].num,average[i]);
}
这样应该可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询