-4

Alright, so I'm using C++ Bloodshed to do a program for my college assignment, and there are a ton of errors that I keep getting, such as 'syntax error before ')' token', 'syntax error before 'else', and 'syntax error at end of input'. Here is the code, if you can help me out I would really appreciate it.

#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;
     }
  • 3
    Check semicolons. **Count braces**. But first of all fix the indentation. – Some programmer dude Dec 17 '13 at 10:47
  • FYI syntax for a for loop goes like this: `for (int i=0; i – Ranveer Dec 17 '13 at 10:48
  • First off, expressions inside a `for` statement are separated with `;`, not `,`. Then you've got a bunch of semicolons where there shouldn't be. Then things like `'bananas'`, they don't do what you think they do (see [multi character literals.](http://stackoverflow.com/questions/3960954/c-multicharacter-literal)). Then... I give up. – jrok Dec 17 '13 at 10:48
  • Same goes for your `set_units()` function. Just by looking at it you can see that there is something wrong with those if-then statements. You have 6 opening braces and only 4 closing ones. – s3rius Dec 17 '13 at 10:48
  • 4
    This question appears to be off-topic because it is about fixing multiple syntax errors. – Frédéric Hamidi Dec 17 '13 at 10:49
  • 3
    Great title. Summarizes my life. – jogojapan Dec 17 '13 at 10:50
  • 1
    @jogojapan You should go out more, then :) – jrok Dec 17 '13 at 10:51
  • OMG! Who taught you this kind of C++??! – Ranveer Dec 17 '13 at 10:51
  • 1
    And get a better compiler ASAP. GCC/Clang for Linux and MSVC for Windows are the main ones. – Simple Dec 17 '13 at 10:52

3 Answers3

1

Presumably, the error message points you to this line

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

You've written , where you meant ;

Once you've fixed that, the first error message will probably point you at or near

switch (grades[index]);

where you've got a rogue ;

Then it will point you at the scrambled if...else formatting in set_units, which should look something like

if (...) {
   ...
} else if (...) {
   ...
} else {
   ...
}
Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • just an update: i've tried doing the extra work, and then the errors sort of multiplied - errors like "in function 'void award_grades()'", "in function 'void set_units()'", and the syntax errors for the else statements are still there. – Professor Lemur Dec 17 '13 at 10:57
  • @ProfessorLemur: If the syntax errors for the `else` statements are still there, then the syntax is still wrong. Do they look like my example, with no extra `{`, `}`, or `;` anywhere? – Mike Seymour Dec 17 '13 at 10:59
  • I can safely say that the syntax errors for else are now gone; now there are just the "in function" errors and the syntax error at end of input. – Professor Lemur Dec 17 '13 at 11:04
  • @ProfessorLemur: "In function" isn't itself an error - it's telling you where to look for the following error or warning. The remaining warnings in `award_grades` are because you're not sure whether `grades[index]` should be a single character like `'d'`, or a string like `"distinction"`. You'll need to check what the input is supposed to be (single characters only, or whole words), and fix the logic accordingly. (You can use `switch` on a single character, but you'll need `if...else` to select code based on a string's value). – Mike Seymour Dec 17 '13 at 11:06
  • This leaves just the end of input error. I tried "end", }, and a ;, but nothing seems to leave it. Any ideas? Thanks so much for your help, by the way. – Professor Lemur Dec 17 '13 at 11:08
  • @ProfessorLemur: Tidy up the indentation so that you can see which block(s) are missing `}` at the end. Then add the missing `}` in the right place. – Mike Seymour Dec 17 '13 at 11:11
  • I finally done this; I ended up with linker errors to undefined references to 'load_units()' and 'award_points()'. Other than that, I'm all clear. Thanks, you are a lifesaver. – Professor Lemur Dec 17 '13 at 11:15
0

First, your commas should be semi-colons:

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

Second, you have a semi-colon after your switch:

switch (grades[index])

Third, you cannot use a switch for a string, let alone a multi-character char. It will convert it to a large-ass number, which is probably not what you want. Instead you need to refactor it to if statements.

0

Linker errors are occuring because you have defined prototypes of functions load_units and award_points :-) If you define bodies of these functions you will not get the errors. BTW this look just like my assignemnt on my first year in Computer Games Development :-) Good luck.

XAMlMAX
  • 2,268
  • 1
  • 14
  • 23