大量的编译器错误

An awful lot of compiler errors

本文关键字:错误 编译器      更新时间:2023-10-16

好吧,我正在用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;
     }

大概,错误消息指向这行

for (index=0, index<10, index=index+1)

你写了,,意思是;

一旦你解决了这个问题,第一条错误消息可能会将你指向或接近

switch (grades[index]);

你有一个流氓;

然后它会指向set_units中的加扰if...else格式,它看起来应该有点像

if (...) {
   ...
} else if (...) {
   ...
} else {
   ...
}

首先,逗号应该是分号:

for (index=0; index<10; index=index+1)

第二,你的switch:后面有一个分号

switch (grades[index])

第三,不能将switch用于string,更不用说多字符char了。它会把它转换成一个大屁股数字,这可能不是你想要的。相反,您需要将其重构为if语句。

Linker错误正在发生,因为您已经定义了函数load_unitsaward_points:-的原型。)如果您定义这些函数的主体,您将不会得到错误。顺便说一句,这看起来就像我在电脑游戏开发第一年的任务:-)祝你好运