Thread: Local function definitions are illegal error?

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    24

    Local function definitions are illegal error?

    I keep getting this error

    error C2601: 'find_ave_bal' : local function definitions are illegal


    that is pointing to this code

    Code:
    	double find_ave_bal(int ID [], int num_bal)
    	
    	{	
    		double subtotal = 0;
    		double total;
    
    		for (int j = 0; j < num_bal; j++)
    		{
    			subtotal += ID [j];
    		}
    			total = subtotal / num_bal;
    
    		return total;
    
    	}
    }

    and this is the code that comes directly before it

    Code:
    	//display output in table form
    
    	cout<<"ID Number"<<setw(16)<<"Balance"<<setw(20)<<"Difference from Average"<<endl;
    
    		for ( ID[j] = 0; ID[j] < n; ID[j] = ID[j] + 1)
    		{
    			cout<<setw(4)<<ID [j]<<setprecision(2)
    				<<setiosflags(ios::fixed | ios::showpoint)
    				<<setw(16)<<bal<<setw(20)<<setprecision(2)
    				<<setiosflags(ios::fixed | ios::showpoint)
    				<<find_ave_bal (ID [j], num_bal)<<endl;
    		}
    		
    	return 0;
    }

    I can't seem to figure out why I am getting this error. It is the only error I am getting at this point and so far, everything that I have tried has not worked. Thanks in advance for any help

    GrlNewB

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    i told you it will almost certainly be a missing brace. zip up your project and ill take a gander.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    24
    I hope this works... thanks for the help!!
    Much Appreciated!

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    I have taken the crap from your source so that the problem is now easily highlighted. fix it yourself.
    Code:
    //Alicia Harris
    //Open Lab 7
    //CSIS 240
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    //function prototype
    
    double find_ave_bal(int, int);
    
    //main function
    int main ()
    {	
    	int n, j;
    	int ID [100] = {0};
    	int bal [100] = {0};
    	int num_bal;
    	double ave_bal;
    	double sum_bal;
    	
    	//Loop to input the ID and balance
    
    	for (n = 0; n < 100; ++n) // this loop has no ending brace FIXME
    	{
    	    cout<<"Please enter the account ID and account balance, -1 to to stop: "<<endl;
    	    cin>>ID[j]>>bal[n];
    	    if (ID[j] < 1000 || ID[j]	> 9999)
    	    {	
    		    cout<<"Invalid ID, please reenter: "<<endl;
    	    }
    	
    	    if (bal[n] > 10000)
    	    {
    		    cout<<"Invalid Balance, please reenter: "<<endl;
    	    }
    	    cout<<"ID Number"<<setw(16)<<"Balance"<<setw(20)<<"Difference from Average"<<endl;
    		for ( ID[j] = 0; ID[j] < n; ID[j] = ID[j] + 1)
    		{
    			cout<<setw(4)<<ID [j]<<setprecision(2)
    				<<setiosflags(ios::fixed | ios::showpoint)
    				<<setw(16)<<bal<<setw(20)<<setprecision(2)
    				<<setiosflags(ios::fixed | ios::showpoint)
    				<<find_ave_bal (ID [j], num_bal)<<endl;
    		}
    		
    	return 0;
    }
    
    double find_ave_bal(int ID [], int num_bal)
    {	
    		double subtotal = 0;
    		double total;
    
    		for (int j = 0; j < num_bal; j++)
    			subtotal += ID [j];
    		total = subtotal / num_bal;
    		return total;
    
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM