好吧,所以我正在使用C ++ Bloodshed为我的大学任务做一个程序,并且我一直有很多错误,比如 '之前的语法错误')'token','else'之前的语法错误,以及'输入结束时的语法错误'。 这是代码,如果你可以帮助我,我会非常感激。
#include<cstdlib>
#include<iostream>
#include<string>
using namespace std;
int points=0; //this is a global variable. it's made of variables and planets.
string studentID;
string units[10]; //global array of ten game matches in total.
char grades[10]; //these are the global medals that are awarded.
void intro();
void load_units(); //this, the above and the below are all prototypes; defines what the function is.
void award_grades();
void award_points();
void set_units();
int main(int argc, char* argv[])
{
intro();
load_units();
award_grades();
award_points();
cout<<"You have achieved..."<<points<<endl;
set_units();
system("PAUSED!!!!");
return EXIT_SUCCESS;
}
void intro()
{
cout<<"Welcome to the Grading System for BTEC!"<<endl;
cout<<"This app will determine your grades, with either Pass, Merit, or Distinction." <<endl;
cout<<"Please enter your name to continue."<<endl;
cin>>studentID;
}
void load_points()
{
units[0]="NOCN";
units[1]="Animation";
units[2]="Game Designing";
units[3]="OSS";
units[4]="HCI";
units[5]="Digital Art";
units[6]="SAD";
units[7]="Project Planning";
units[8]="Procedural Programming";
units[9]="Database Design";
}
void award_grades()
{
int index; //This is a local variable. It more or less allows for a global variable's value to be retained.
for (index=0; index<10; index=index+1)
{
{
cout<<"What grade did you get for the"<<units[index]<<"unit?"<<endl;
cin>>grades[index];
}
void award_points();
for (index=0, index<10, index=index+1)
switch (grades[index]);
{
case'distinction':
points=points +3; //Code for the event points. The following are also event codes...
break;
case'merit':
points=points +2;
break;
case'pass':
points=points +1;
break;
case'd':
points=points +3;
break;
case'm':
points=points +2;
break;
case'p':
points=points +1;
break;
}
}
}
void set_units()
{
if(points>13)
{// if the points are more than 13 then...
cout<<studentID + "Well done! You have a distinction!"<<endl;
}
{
else if(points<8);//otherwise, if points are more than 8 but below more than 13, then...
cout<<studentID+"Congratulations, you have a merit!"<<endl;
}
{
else if(points<3); //If the points are more than 3 but not more than 8 then...
cout<<studentID+"You have a pass! Try to keep it up and get a higher grade."<<endl;
}
{
else; //if none of these conditions are met, then...
{
cout<<studentID + "Your studentID is not enlisted. Either enrol, or re-enter your name correctly. Remember, it's case-sensitive."<<endl;
}
答案 0 :(得分:1)
据推测,错误消息指向此行
for (index=0, index<10, index=index+1)
您已将,
写为;
一旦你修复了它,第一条错误信息可能会指向你或附近
switch (grades[index]);
你有一个流氓;
然后它会指向if...else
中的加扰set_units
格式,它看起来像
if (...) {
...
} else if (...) {
...
} else {
...
}
答案 1 :(得分:0)
首先,你的逗号应该是分号:
for (index=0; index<10; index=index+1)
其次,在switch
:
switch (grades[index])
第三,你不能switch
使用string
,更不用说多字符char
了。它会将它转换为大屁股,这可能不是你想要的。相反,你需要将它重构为if语句。
答案 2 :(得分:0)
链接器错误正在发生,因为您已定义函数原型load_units
和award_points
:-)
如果您定义这些函数的主体,则不会得到错误。
顺便说一下这个看起来就像我在电脑游戏开发的第一年我的同意:-)
祝你好运。