Thread: local function & unexpected end Help

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    9

    Exclamation local function & unexpected end Help

    Can someone please help me out...

    Here's my code:

    Code:
    //Chris Adams
    //CIS 111 Lab Assignment # 6
    
    //includes
    #include <fstream>
    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    using namespace std;
    
    //void function declaration
    void process (ifstream& in_stream, ofstream out_stream);
    void costwd ( );
    void costwe ( );
    	
    int time;
    int minutes;
    int cost;
    ifstream fin;
    ofstream fout;
    
    int main( )
    {
    	//local variable declarations
    
    
    	//input/output files preparation
    	fin.open("record.txt");
    	if (fin.fail( ))
    	{
    		cout << "Sorry, but the process of opening the input file failed.\n";
    		exit(1);
    	}
    
    	fout.open("bill.txt");
    	if (fout.fail( ))
    	{
    		cout << "Sorry, but the process of opening the output file failed.\n";
    		exit(1);
    	}
    
    	//calling void function
    	process (fin, fout);
    
    	fin.close( );
    	fout.close( );
    
    	//ending prorgram
    	cout << "Ending process of editing preparing your phone bill.\n";
    	cout << "Thank You.";
    	return 0;
    }
    
    
    //-----------------------------------------------------------------------
    
    
    //void function
    void add_name (ifstream& in_stream, ofstream out_stream)
    {
    	//local void functions variable declarations
    char day;
    
    
    
    	//process procedure for weekend
    	while(!in_stream.eof())
    {
    	in_stream>>day;
    	in_stream>>time;
    	in_stream>>minutes;
    
    	if (day != 'S')
    	{
    	void costwe ( );
    	}
    
    	else
    	{
    	void costwd ( );
    	}
    	//perform calculations and output
    	//the variables and the calculations
    }
    //--------------------------------------------
    //function call
    
    //
    
    
    void costwd ( )
    *{
    	if( (time >= 8) && (time <= 18))
    	{
    		cost = minutes * .40;
    	}
    	else
    	{
    		cost = minutes * .25;
    	}
    
    	fout << cost;
    }
    //==============================
    
    *void costwe ( )
    {	
    	cost = minutes * .15;
    	
    	fout  <<  cost;
    }
    *



    1st & 2nd *: error C2601: 'costwd' : local function definitions are illegal
    3rd *: fatal error C1004: unexpected end of file found


    Can someone please help me out with this....


    Thanks a million...
    Last edited by Captn Japan; 04-14-2003 at 01:45 PM.

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    watch your brackets. you aren't closing the while loop in add_name() . I haven't tried to build it but that seems to be the problem at first glance
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Change this:

    Code:
    if (day != 'S')
    {
        void costwe ( );
    }
    
    else
    {
        void costwd ( );
    }
    To this:

    Code:
    if( day != 'S' )
    {
        costwe();
    }
    
    else
    {
        costwd();
    }
    The addition of the void keyword made the compiler think you are trying to define a function within another function... hence the error message you got.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    9
    I got rid of all the 'voids' for those two functions but now I'm getting this:

    Code:
    costwd ( )
    *{
    	if( (time >= 8) && (time <= 18))
    	{
    		cost = minutes * .40;
    	}
    	else
    	{
    		cost = minutes * .25;
    	}
    
    	fout << cost;
    }
    //==============================
    
    costwe ( )
    *{	
    	cost = minutes * .15;
    	
    	fout << cost;
    }
    *


    1st & 2nd *:error C2143: syntax error : missing ';' before '{'
    3rd *: fatal error C1004: unexpected end of file found


    I have no clue how to fix these errors because the 1st&2nd errors shouldn't be like that because I don't want the ';' there cause it's a function call, right?.

    I still have no clue how to fix the 3rd error...



    If anyone can shed some light for me, please do...

    Thanks.

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    he didn't say remove all the voids he said just those two.

    you shouldn't have it inside the calling function.

    and the end bracket on that while loop is still a problem in case you glossed over that. It makes the compiler think that you're still inside that first function when you define the last two.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    problems:

    1: while loop needs closing brackets
    2: the two voids that were mentioned previously
    3: the asterisks you have living around the two bottom functions
    4: missing process() function
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM