本人是初学者,写了一个代码但是不知道如何改错,请各位路过的高手帮帮忙
本人是菜鸟,写了一个代码但是不知道怎么改错,请各位路过的高手帮帮忙
#include <stdio.h>
#define N 5
struct student{
char name[8];
char num[6];
int score[5];
}stu[N];
input(struct student stu[])
{
int i,j ;
for(i=0;i<N;i++){
printf("\n please input %d of %d\n",i+1,N);
printf("ѧºÅÊÇ£º\t");
scanf("%s",stu[i].num);
printf("ÐÕÃûÊÇ:\t");
scanf("%s",stu[i].name);
for (j=0;j<3;j++){
printf("\nµÃ·ÖÊÇ:\n",j+1);
scanf("%d",&stu[i].score[j]);
}
printf("\n");
}
}
void main(){
input (stu);
int pos = 0;
int i;
int maxscore=stu[0].score;
for(i=0;i<3;i++){
if( maxscore<stu[i].score){
maxscore=stu[i].score;
pos = i;
}
}printf("\n %s %s maxscore=%d",stu[pos].name,stu[pos].num,maxscore);
}
错误提示:c:\users\administrator\desktop\1.cpp(23) : warning C4508: 'input' : function should return a value; 'void' return type assumed
c:\users\administrator\desktop\1.cpp(29) : error C2440: 'initializing' : cannot convert from 'int [5]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\users\administrator\desktop\1.cpp(31) : error C2446: '<' : no conversion from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\users\administrator\desktop\1.cpp(31) : error C2040: '<' : 'int' differs in levels of indirection from 'int [5]'
c:\users\administrator\desktop\1.cpp(32) : error C2440: '=' : cannot convert from 'int [5]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Ö´ÐÐ cl.exe ʱ³ö´í.
1.obj - 1 error(s), 0 warning(s)
------解决方案--------------------
不是说的很明白吗?
1:你的“input”函数应当返回一个值(因为你没有定义返回类型),但你没有任何return。
2:你企图把int[]或者int*赋给int,或者对这些类型使用比较操作符。
------解决方案--------------------
不知道你想要干什么,又几处错误你改下~~
1、input函数加上返回类型~ void input(struct student stu[])
2、你这句肯定不对 int maxscore=stu[0].score;
你定义的时候定义的是 int score[5],你现在赋值没明确赋值的是哪个~
maxscore=stu[0].score[0];这样赋值就对了。
下面也是这种错误,不知道你要干什么,所以自己看着改把~~
------解决方案--------------------
1、input(struct student stu[]) 函数定义不对
函数定义如下 返回值类型 函数名(参数列表)。
2、结构体定义有问题 typedef struct Name{} name 就可以了 如果你要一个结构体数组完全可以在使用的时候定义。 如 name n[N] 就可以了。
3、结构体里定义的score 直接定义成int 或者float就行了,不用整形数组
4、scanf里面要取地址
先把这些问题改了吧。。。
Good Luck。。。
#include <stdio.h>
#define N 5
struct student{
char name[8];
char num[6];
int score[5];
}stu[N];
input(struct student stu[])
{
int i,j ;
for(i=0;i<N;i++){
printf("\n please input %d of %d\n",i+1,N);
printf("ѧºÅÊÇ£º\t");
scanf("%s",stu[i].num);
printf("ÐÕÃûÊÇ:\t");
scanf("%s",stu[i].name);
for (j=0;j<3;j++){
printf("\nµÃ·ÖÊÇ:\n",j+1);
scanf("%d",&stu[i].score[j]);
}
printf("\n");
}
}
void main(){
input (stu);
int pos = 0;
int i;
int maxscore=stu[0].score;
for(i=0;i<3;i++){
if( maxscore<stu[i].score){
maxscore=stu[i].score;
pos = i;
}
}printf("\n %s %s maxscore=%d",stu[pos].name,stu[pos].num,maxscore);
}
错误提示:c:\users\administrator\desktop\1.cpp(23) : warning C4508: 'input' : function should return a value; 'void' return type assumed
c:\users\administrator\desktop\1.cpp(29) : error C2440: 'initializing' : cannot convert from 'int [5]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\users\administrator\desktop\1.cpp(31) : error C2446: '<' : no conversion from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\users\administrator\desktop\1.cpp(31) : error C2040: '<' : 'int' differs in levels of indirection from 'int [5]'
c:\users\administrator\desktop\1.cpp(32) : error C2440: '=' : cannot convert from 'int [5]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Ö´ÐÐ cl.exe ʱ³ö´í.
1.obj - 1 error(s), 0 warning(s)
------解决方案--------------------
不是说的很明白吗?
1:你的“input”函数应当返回一个值(因为你没有定义返回类型),但你没有任何return。
2:你企图把int[]或者int*赋给int,或者对这些类型使用比较操作符。
------解决方案--------------------
不知道你想要干什么,又几处错误你改下~~
1、input函数加上返回类型~ void input(struct student stu[])
2、你这句肯定不对 int maxscore=stu[0].score;
你定义的时候定义的是 int score[5],你现在赋值没明确赋值的是哪个~
maxscore=stu[0].score[0];这样赋值就对了。
下面也是这种错误,不知道你要干什么,所以自己看着改把~~
------解决方案--------------------
1、input(struct student stu[]) 函数定义不对
函数定义如下 返回值类型 函数名(参数列表)。
2、结构体定义有问题 typedef struct Name{} name 就可以了 如果你要一个结构体数组完全可以在使用的时候定义。 如 name n[N] 就可以了。
3、结构体里定义的score 直接定义成int 或者float就行了,不用整形数组
4、scanf里面要取地址
先把这些问题改了吧。。。
Good Luck。。。