Declaration syntax error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blondie1966
    New Member
    • Mar 2010
    • 12

    Declaration syntax error

    Im trying to write a program about a truck inventory with trucks coming and going and the amount in each one, but keep coming up with declaration syntax error.. Any help would be greatly appreciated. Im using Borland C++. Thanks


    Code:
    #include <iostream.h>
    #include <iomanip.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <string.h>
    #include <ctype.h>
    
    #define max_trucks 50
    
    class TRUCKS
    {
    	private :
    	int TRUCK_NUM;
    	int TRUCK_CAP;
    	int DON_ON_HAND;
    	static int NUM_TRUCKS;
    
    	public :
    	TRUCK (int id, int don=0);
    	int ADD_TRUCK (int don);
    	int REMOVE_TRUCK (int don);
    	inline int GET_TRUCK_NUM () {return TRUCK_NUM;}
    	inline int GET_CAP () {return TRUCK_CAP;}
    	inline int GET_CONT () {return DON_ON_HAND;}
    	static int TOTAL_TRUCKS();
    };
    
    int NUM_TRUCKS = 0
    	{
    	TRUCK_NUM = id;
    	CAP_ON_HAND = don;
    	TRUCK_CAP = 250;
    	++NUM_TRUCKS;
    	}
    	TRUCK: :TRUCK ()
    	{
    		delete [] TRUCK_ID;
    	}
    	int TRUCK: :TOTAL_TRUCKS ()
    	{
    		return NUM_TRUCKS;
    	}
    
    	TRUCK* create_truck ();
    	void display (TRUCKS&);
    	truck_table
    	{
    	void main ()
    
    		create_truck,
    		truck_table;
    		int don_amt = 250,
    			result,
    			count = 0,
    			choice;
    			max_trucks;
    		char select = ' ';
    		char answer = ' ';
    
    			 [max_trucks];
    
    		do
    		{
    			cout << "\n\nPlease choose a number from the menu below";
    			cout << "\n1. Add a truck";
    			cout << "\n2. Add donations to truck";;
    			cout << "\n3. Remove a Truck";
    			cout << "\n4. Display the trucks";
    			cout << "\n5. Quit the program";
    			cout << "\n\nPlease enter your selection now: ";
    			cin >> select;
    			clrscr ();
    
    			switch (select)
    			{
    				case '1':
    					cout << "\nDo you want to add a truck to inventory?(Y/N): ";
    					cin >> answer;
    					while (toupper(answer) == 'Y' && count, max_trucks)
    					{
    						truck_table[count] = create_truck ();
    						++count;
    						cout << "\nDo you want to add a truck to inventory?(Y/N): ";
    						cin >> answer;
    					}
    					break;
    				case '2':
    					cout << "\nTo whick truck would you like to add donations? (1-50) : ";
    					cin >> choice;
    					if (choice < 1 || choice > count)
    					{
    						cout << "\n\nINVALID ENTRY!!! ";
    						break;
    					}
    					else
    					{
    						cout << "\nPlease enter the amount of donations to add: ";
    						cin >> don_amt;
    						result = truck_table [choice - 1]->ADD_DON (don_amt);
    						if (result < 0)
    							cout << "\nERROR Truck capacity is not large enough!!!\n";
    						else
    							cout << "\nDonations added!!! ";
    						break ;
    					}
    				case '3' :
    					for (int x = 0; x < count; ++x)
    						display (*truck_table [x]);
    					break ;
    				}
    			}
    			while (select != '4');
    				cout << "\n\n\n\n							THANK YOU";
    				cout << "\n\n							GOODBYE";
    			for (int x = 0; x < count; ++x)
    				delete truck [x] ;
    		}
    
    	TRUCK* create()
    	{
    		int truck_num,
    			donations + 0;
    		char name [80];
    
    		TRUCK* truckptr;
    
    		cout << "\nPlease enter the truck number: ";
    		cin >> truck_num;
    		cin.ignore (81, '\n');
    		cout << "\nPlease enter the amount of donations in truck: ";
    		cin >> donations;
    		cin.ignore (81, '\n');
    		clrscr ();
    		truckptr = new TRUCK(truck_num, donations);
    		cout << "\n\nTrucks in inventory : " truckptr->TOTAL_TRUCKS ();
    		return truckptr;
    	}
    
    	void display (TRUCK& truck)
    	{
    		cout << "\n\nTruck num " << truck. GET_TRUCK_NUM ();
    		cout << "\nTruck capacity: " << truck. GET_CAP ();
    		cout << "\nDonations on hand: " << truck. GET_CONT ();
    	}
    Last edited by Banfa; Mar 7 '10, 12:59 PM. Reason: Added [code] ... [/code] tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    It would greatly help us if you would post the exact errors you are getting and indicate on what lines of the posted listing they occur.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      However I notice that

      Line 10/19: constructor name does not match class name

      Line 29: Ransom code not actually in a function

      Line 10/39 Declaration/definition class name mismatch

      Line 48: main returns int NOT void, not { indicating the start of the main function.

      Line 50, 51, 56: Random symbols not defined anywhere else

      Line 60: random array syntax not attached to any symbol name

      Points on style

      class TRUCK(S) it is unusual styling, though not strictly wrong, for a class name to be all in capital letters and similarly it is also unusual styling for all member names to be in capitals. In my company all caps is reserved for consts and static consts.

      Line 119: The factory function to create a TRUCK could be and probably would be better being a static member function of the class TRUCK

      Line 139: a function like this to output a TRUCK would be better off being a member of TRUCK, however an alternitive would be to make an iostream helper function that handles the truck type allowing

      cout << truck;

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        Also, :: (two colons) in scope resolution, like Classname::Func tionname().... should not have space between them.

        Comment

        • Blondie1966
          New Member
          • Mar 2010
          • 12

          #5
          declaration syntax errors are on line 29 and 47 thanks for help

          Comment

          • sridhard2406
            New Member
            • Dec 2007
            • 52

            #6
            In c++, main will have return type is int, you should mention as
            int main( ),

            Please try with, let us know, ur facing any other declaration error.

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              Originally posted by Blondie1966
              declaration syntax errors are on line 29 and 47 thanks for help
              You are missing ; at the end of lines 28 and 46.

              It is not uncommon for compiler errors to be reported on the first code line after then line with the error in it, particularly for things like missing ; and other syntax errors were the compiler can not tell there is a syntax error until it reads in the next bit of actual code.

              Comment

              • Blondie1966
                New Member
                • Mar 2010
                • 12

                #8
                putting ; at the end of 28 and 46 didnt make any difference acutally give me a 3rd error

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  You may want to consider fixxing all the other issues I raised in post #3 and that other people have pointed out.

                  It is not unheard of of a syntax error to be hiding someother error in the code that only shows up after fixing the syntax error.

                  Your compile process (as a beginner) show be
                  1. Compile the code
                  2. If there are no errors and warnings stop
                  3. Fix the first error in compiler output the listing
                  4. goto 1


                  Once you gain experience you can fix more than one error at step 3 because you will learn which messages can be ignored as a symptom of a previous error.

                  Comment

                  • Blondie1966
                    New Member
                    • Mar 2010
                    • 12

                    #10
                    ok I have went step by step and started with part of the program and compiled it slowly as I went and still having issues, I am like at the point that I have changed things so much that I am now totally lost to what I am doing and writing..I do appreciate everyones help but gettin to frustrated..you would think it would be something simple that I am overlooking but i have sat at it too long and cant seem to see whats wrong Thanks all

                    Comment

                    • Banfa
                      Recognized Expert Expert
                      • Feb 2006
                      • 9067

                      #11
                      If you have done a lot of changes I suggest you repost your code, remembering to put [code]...[/code] tags round it.

                      Comment

                      • Blondie1966
                        New Member
                        • Mar 2010
                        • 12

                        #12
                        Can I ask if anyone has run this program and not have any errors?? If so what did you change in order for it to work? Thanks

                        Comment

                        Working...