I don't know how to declare the funtions before it reach the int main?

#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;





//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void closeFile()
{
   input.close();
}    



//-----------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------
void PressAnyKeyToContinue(void)
{
     system("pause");   //pauses the system until you press a key
     system("cls");     //clears the screen
}    



//-----------------------------------------------------------------------------
//  Display A basic report Header
//-----------------------------------------------------------------------------
void DisplayHeader(void)
{
   cout << "Name\tCP1\tMath\tEnglish" <<endl; 
   cout << "---------------------------------------------" <<endl;
}

 
//-----------------------------------------------------------------------------
//  Example view the contents of a file
//-----------------------------------------------------------------------------
void ViewAllInformation()
{
 int m1,m2,m3;
 string name;

 openFile();                           // must open the file before use
 DisplayHeader();
 while (!input.eof())                  // stop if End Of File is reached
 {
     input >> name >> m1 >> m2 >> m3;  // reads a line from the file
     if (!input.fail())                // checks if the last line is read
     {
             
       cout << name << "\t"<< m1 << "\t"<< m2 << "\t"
            << m3<< endl;
     }             
 }
 
 closeFile();                          // must close the file
 cout << endl << endl;                 // create 2 empty lines after display
}




//------------------------------------------------------------------------------
//  A menu item 2 sample module showing how to implement menu items
//  as functions
//------------------------------------------------------------------------------
void TestOption(void)
{
     cout << "Display a submenu or display Information" 
          << endl<< endl;
}  
//-----------------------------------------------------------------------------
// A function that displays a menu and returns the option selected as an integer 
// number
//-----------------------------------------------------------------------------






int MainMenu (void)
{
    int choice=0;
    bool gotInput = false;
    
    cout << "=====================================" << endl;
    cout << " Main Menu" << endl;
    cout << "=====================================" << endl;
    cout << "1. View all information" << endl;
    cout << "2. Statistics By Subject " << endl;
    cout << "3. Overall Statistics" << endl;
    cout << "4. Exit" << endl;
    cout << "=====================================" << endl;
    
    do {                                         //Do not modify this loop 
        cout << "Please input your choice:";   //and accept it as it is.
        if(!(cin >> choice))                   //loop to make sure
            {                                      //that only valid options
            cin.clear();                     //are entered. 
            cin.ignore(10000,'\n');
            gotInput = true;
         }
         if (choice >= 1 && choice<=9) gotInput = true;
    } while(!gotInput);     
    return choice;                                 //return the selected choice   
}    



//-----------------------------------------------------------------------------
//            The main function where execution starts
//-----------------------------------------------------------------------------
int main()
{
  int choice;
  bool flag = false;                      
  int m1,m2,m3;
  string name;

  // 
  //This loop will interpret the menu selection 
  // and executes the correct module (function). 
  //It will terminate if the selection is 4
  //
  
  do{
      choice = MainMenu();     //get the choice
      system("cls");
      if (choice == 1) ViewAllInformation();      
      else if (choice == 2) TestOption();
      else if (choice == 3) TestOption();
      else if (choice == 4) flag = true;
      else cout << "use only number shown in the menu" << endl;  
      if(!flag) PressAnyKeyToContinue();
   }while (!flag);
   
   
   
int English 
{
    int choice=0;
    bool gotInput = false;
    bool flag = false; 
    
    cout << "=====================================" << endl;
    cout << "Statistis of CPI" << endl;
    cout << "=====================================" << endl;
    cout << "1. Overall" << endl;
    cout << "2. Display list of students based on grade " << endl;
    cout << "3. Exit" << endl;
    cout << "=====================================" << endl;
    
    do {                                         //Do not modify this loop 
        cout << "Please input your choice:";   //and accept it as it is.
        if(!(cin >> choice))                   //loop to make sure
            {                                      //that only valid options
            cin.clear();                     //are entered. 
            cin.ignore(10000,'\n');
            gotInput = true;
         }
         if (choice >= 1 && choice<=9) gotInput = true;
    } while(!gotInput);     
    return choice;                                 //return the selected choice   
    
    
    
      do{
      choice = ViewInformation();     //get the choice
      system("cls");
      if (choice == 1) ();      
      else if (choice == 2) ();
      else if (choice == 3) flag = true;
      else cout << "use only number shown in the menu" << endl;  
      if(!flag) PressAnyKeyToContinue();
   }while (!flag);
  
}    


int Math 
{
    int choice=0;
    bool gotInput = false;
    bool flag = false; 
    
    cout << "=====================================" << endl;
    cout << "Statistis of CPI" << endl;
    cout << "=====================================" << endl;
    cout << "1. Overall" << endl;
    cout << "2. Display list of students based on grade " << endl;
    cout << "3. Exit" << endl;
    cout << "=====================================" << endl;
    
    do {                                         //Do not modify this loop 
        cout << "Please input your choice:";   //and accept it as it is.
        if(!(cin >> choice))                   //loop to make sure
            {                                      //that only valid options
            cin.clear();                     //are entered. 
            cin.ignore(10000,'\n');
            gotInput = true;
         }
         if (choice >= 1 && choice<=9) gotInput = true;
    } while(!gotInput);     
    return choice;                                 //return the selected choice   
    
    
    
      do{
      choice = ViewInformation();     //get the choice
      system("cls");
      if (choice == 1) ();      
      else if (choice == 2) ();
      else if (choice == 3) flag = true;
      else cout << "use only number shown in the menu" << endl;  
      if(!flag) PressAnyKeyToContinue();
   }while (!flag);
  
}    


int CPI 
{
    int choice=0;
    bool gotInput = false;
    bool flag = false; 
    
    cout << "=====================================" << endl;
    cout << "Statistis of CPI" << endl;
    cout << "=====================================" << endl;
    cout << "1. Overall" << endl;
    cout << "2. Display list of students based on grade " << endl;
    cout << "3. Exit" << endl;
    cout << "=====================================" << endl;
    
    do {                                         //Do not modify this loop 
        cout << "Please input your choice:";   //and accept it as it is.
        if(!(cin >> choice))                   //loop to make sure
            {                                      //that only valid options
            cin.clear();                     //are entered. 
            cin.ignore(10000,'\n');
            gotInput = true;
         }
         if (choice >= 1 && choice<=9) gotInput = true;
    } while(!gotInput);     
    return choice;                                 //return the selected choice   
    
    
    
      do{
      choice = ViewInformation();     //get the choice
      system("cls");
      if (choice == 1) ();      
      else if (choice == 2) ();
      else if (choice == 3) flag = true;
      else cout << "use only number shown in the menu" << endl;  
      if(!flag) PressAnyKeyToContinue();
   }while (!flag);
  
}    


int MenuSubject 
{
    int choice=0;
    bool gotInput = false;
    bool flag = false; 
    
    cout << "=====================================" << endl;
    cout << " Statistic By Menu Subject" << endl;
    cout << "=====================================" << endl;
    cout << "1. CPI" << endl;
    cout << "2. Mathematics " << endl;
    cout << "3. English" << endl;
    cout << "4. Exit" << endl;
    cout << "=====================================" << endl;
    
    do {                                         //Do not modify this loop 
        cout << "Please input your choice:";   //and accept it as it is.
        if(!(cin >> choice))                   //loop to make sure
            {                                      //that only valid options
            cin.clear();                     //are entered. 
            cin.ignore(10000,'\n');
            gotInput = true;
         }
         if (choice >= 1 && choice<=9) gotInput = true;
    } while(!gotInput);     
    return choice;                                 //return the selected choice   
    
    
    
      do{
      choice = ViewInformation();     //get the choice
      system("cls");
      if (choice == 1) CPI();      
      else if (choice == 2) Math ();
      else if (choice == 3) English();
      else if (choice == 4) flag = true;
      else cout << "use only number shown in the menu" << endl;  
      if(!flag) PressAnyKeyToContinue();
   }while (!flag);
  
}    

int ViewInformation
{
    int choice=0;
    bool gotInput = false;
    bool flag = false; 
    
    cout << "=====================================" << endl;
    cout << " View Information" << endl;
    cout << "=====================================" << endl;
    cout << "1. View all information" << endl;
    cout << "2. Statistics By Subject " << endl;
    cout << "3. Overall Statistics" << endl;
    cout << "4. Exit" << endl;
    cout << "=====================================" << endl;
    
    do {                                         //Do not modify this loop 
        cout << "Please input your choice:";   //and accept it as it is.
        if(!(cin >> choice))                   //loop to make sure
            {                                      //that only valid options
            cin.clear();                     //are entered. 
            cin.ignore(10000,'\n');
            gotInput = true;
         }
         if (choice >= 1 && choice<=9) gotInput = true;
    } while(!gotInput);     
    return choice;                                 //return the selected choice   
    
    
    
      do{
      choice = ViewInformation();     //get the choice
      system("cls");
      if (choice == 1) ViewAllInformation();      
      else if (choice == 2) MenuSubject();
      else if (choice == 3)();
      else if (choice == 4) flag = true;
      else cout << "use only number shown in the menu" << endl;  
      if(!flag) PressAnyKeyToContinue();
   }while (!flag);
  
}    
  
   return 0;
}
Attachments
12345  John   80  80  80
12346  Ahmad  80  70  70
12347  Siti   60  60  60
12348  Lim    40  40  40

looks fine up to main. But because of the lack of code tags, I can't tell what's going on after it. Try reading this for your next post, or the words on the input box background that you ignored when you typed over them.

line 187: you forgot the parentheses after the function name. Same with all other functions, so I won't tell you the line numbers.

>>I don't know how to declare the funtions before it reach the int main?

Pretty easy -- just copy the line with the function name to somewhere above main() and add a semicolon after it. For example, after correction line 146 copy it and past to line 7, then line 7 will look something like this: int English (); . I recommend copy/paste method instead of fresh typing to avoid typing mistakes.

line 187: you forgot the parentheses after the function name. Same with all other functions, so I won't tell you the line numbers.

>>I don't know how to declare the funtions before it reach the int main?

Pretty easy -- just copy the line with the function name to somewhere above main() and add a semicolon after it. For example, after correction line 146 copy it and past to line 7, then line 7 will look something like this: int English (); . I recommend copy/paste method instead of fresh typing to avoid typing mistakes.

well i have put the parentheses at all the function and declare the function before it reaches the int main.

after that i compile and this happens
then error said
in function 'int main'
expected primary-expression before ';' before "int"

you're missing the OpenFile() function declaration... and you should initialize functions above main, just like Ancient Dragon said, just writing the name of the function and declaring the parameters involved, like this:

void ViewAllInformation();
...
int main()
{
...
return 0;
}

void ViewAllInformation()
{
...
}

Delete the code and start again.

Seriously, if you think you can write 350+ lines of code in one sitting then expect it to compile right off the bat, then you don't need a forum to help you.

Writing that much code, finding yourself swamped with error messages, then dumping the whole sorry mess on a forum for some other schmuck to fix it is not a long term strategy. You need to find a programming approach which works for you.

Consider this example
Nice simple baby steps all the way. You write a few lines then compile.
It's far easier to find the problem in the few lines you most recently added, if you get new error messages.
As experience grows, then you'll be able to write more code in each step, but only within your ability to deal with the consequences.

In addition, after you've "finished" a function (it compiles), then you also RUN the program to make sure it works as you expect it to work. If it doesn't, then fix it before you add more code.

After every few functions added, make a backup copy of the code in a safe place (say a zip file of the project root directory). Later on, you'll want to learn about source control.

If you do these things, then the questions you get to ask on forums will be much more to the point.
Like for example, "I added these few lines and got an error message I don't understand", or "This version runs, but the next version crashes".

This article has been dead for over six months. Start a new discussion instead.