主题:不知道错误???
773950918
[专家分:0] 发布于 2010-06-24 19:30:00
请问哪里出错啦???
编译好多错误???
#include<iostream>
using namespace std;
#define PERSON 5;
#define COURSE 3;
struct studenttype
{
int id;
char name[20];
int score[COURSE];
int gry;
};
int main()
{
studenttype student [PERSON];
int i,j;
cout<<"--------------------------------"<<endl;
for(i=0;i<PERSON;i++)
{
cin>>student[i].id;
cin>>student[i].name;
student[i].gry=0;
for(j=0;j<COURSE;j++)
{cin>>student[i].score[j];
student[i].gry=student[i].gry+student[i].score[j];
}
student[i].gry=student[i].gry/b;
}
cout<<"-------------------------------------"<<endl;
for(i=0;i<PERSON;i++)
{
cout<<student1[i].id<<"\t"<<student[i].name<<"\t";
for(j=0;j<COURSE;j++)
cout<<student[i].score[j]<<'\t";
cout<<student[i].gry<<endl;
}
return 0;
}
回复列表 (共8个回复)
沙发
雪光风剑 [专家分:27190] 发布于 2010-06-24 19:56:00
首先是这里studenttype student [PERSON];student和[PERSON]之间的空格去掉才对吧
student[i].gry=student[i].gry/b;
这个b哪冒出来的?没声明的野变量哦,呵呵
板凳
773950918 [专家分:0] 发布于 2010-06-25 17:02:00
改了还是很多问题??为什么??
无解??
--------------------Configuration: 结构体1 - Win32 Debug--------------------
Compiling...
结构体1.cpp
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(9) : error C2143: syntax error : missing ']' before ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(9) : error C2059: syntax error : ']'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(9) : error C2238: unexpected token(s) preceding ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(16) : error C2143: syntax error : missing ']' before ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(16) : error C2143: syntax error : missing ';' before ']'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(19) : error C2146: syntax error : missing ')' before identifier 'i'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(19) : error C2059: syntax error : ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(19) : error C2059: syntax error : ')'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(20) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(24) : error C2146: syntax error : missing ')' before identifier 'j'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(24) : error C2059: syntax error : ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(24) : error C2059: syntax error : ')'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(25) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(31) : error C2146: syntax error : missing ')' before identifier 'i'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(31) : error C2059: syntax error : ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(31) : error C2059: syntax error : ')'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(32) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(33) : error C2065: 'student1' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(33) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(33) : error C2228: left of '.id' must have class/struct/union type
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(34) : error C2146: syntax error : missing ')' before identifier 'j'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(34) : error C2059: syntax error : ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(34) : error C2059: syntax error : ')'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(35) : error C2146: syntax error : missing ';' before identifier 'cout'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(35) : error C2001: newline in constant
C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)\结构体1.cpp(36) : error C2146: syntax error : missing ';' before identifier 'cout'
执行 cl.exe 时出错.
结构体1.obj - 1 error(s), 0 warning(s)
3 楼
773950918 [专家分:0] 发布于 2010-06-25 17:07:00
#include<iostream>
using namespace std;
#define PERSON 5;
#define COURSE 3;
struct studenttype
{
int id;
char name[20];
int score[COURSE];
int gry;
};
int main()
{
studenttype student[PERSON];
int i,j;
cout<<"--------------------------------"<<endl;
for(i=0;i<PERSON;i++)
{
cin>>student[i].id;
cin>>student[i].name;
student[i].gry=0;
for(j=0;j<COURSE;j++)
{cin>>student[i].score[j];
student[i].gry=student[i].gry+student[i].score[j];
}
student[i].gry=student[i].gry/COURSE;
}
cout<<"-------------------------------------"<<endl;
for(i=0;i<PERSON;i++)
{
cout<<student1[i].id<<"\t"<<student[i].name<<"\t";
for(j=0;j<COURSE;j++)
{
cout<<student[i].score[j]<<'\t";
cout<<student[i].gry<<endl;
}
}
return 0;
}
4 楼
773950918 [专家分:0] 发布于 2010-06-25 17:07:00
还是很多错误??
5 楼
雪光风剑 [专家分:27190] 发布于 2010-06-25 20:37:00
DEFINE语句不需要用;做结束,把那两个DEFINE后面的分号去掉
6 楼
雪光风剑 [专家分:27190] 发布于 2010-06-25 20:38:00
cout<<student[i].score[j]<<'\t";
还有这里,你的\t两头的引号不一致啊
7 楼
773950918 [专家分:0] 发布于 2010-06-26 14:21:00
好了!大哥请问一下怎样才能提高编程的效率呢??就是要怎样做才能提高编程能力???谢谢@@!
8 楼
tankiy [专家分:30] 发布于 2010-06-27 15:29:00
#include<iostream>
using namespace std;
#define PERSON 5
#define COURSE 3
struct studenttype
{
int id;
char name[20];
int score[COURSE];
int gry;
};
int main()
{
studenttype student [PERSON];
int i,j;
cout<<"--------------------------------"<<endl;
for(i=0;i<PERSON;i++)
{
cin>>student[i].id;
cin>>student[i].name;
student[i].gry=0;
for(j=0;j<COURSE;j++)
{cin>>student[i].score[j];
student[i].gry=student[i].gry+student[i].score[j];
}
student[i].gry=student[i].gry/3;//b没有定义我就改了·
}
cout<<"-------------------------------------"<<endl;
for(i=0;i<PERSON;i++)
{
cout<<student[i].id<<"\t"<<student[i].name<<"\t";
for(j=0;j<COURSE;j++)
cout<<student[i].score[j]<<"\t";
cout<<student[i].gry<<endl;
}
return 0;
}
可以运行了
我来回复