Thread: error C2143

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0

    error C2143


    Hi,
    I wrote a program which gave me 102 errors and 3 warnings. The majority of the 102 errors are "error C2143: syntax error : missing ';' before 'PCH creation point'", while some are "error C2143: syntax error : missing ';' before '{' / ')'".

    Also, my FFS::display(int min, ofstream& outfile) and FFS::closedstall_loss() have the following errors: error C2601: 'display' : local function definitions are illegal.

    My last error was "fatal error C1003: error count exceeds 100; stopping compilation". It points to the "while (!infile.eof())" line in the function that reads input from a text file.

    The 2 warnings are "warning C4552: '<' : operator has no effect; expected operator with side-effect". The < mentioned is supposed to be used as a "greater sign".

    I checked my programs and can't find (or must have missed) any missing ";".

    I've posted my code in the next few posts because it exceeds the character limt.

    Please help and sorry for any incovenience caused!
    Thank you.

    Regards,
    Rayne
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0
    (Part 1 of header file "ffs3.h")

    Code:
    #ifndef		__ffs3_h__
    #define		__ffs3_h__
    
    #include	<iostream>
    #include	<fstream>
    
    using		std::endl;
    using		std::cout;
    using		std::cerr;
    using		std::ios;
    using		std::ifstream;
    using		std::ofstream;
                     
    #define		MaxCus				20	// Maximum number of customer in queue
    #define		MaxTime				20	// The time period that the food is fresh
    #define		MaxCtr				6	// Number of counters
    #define		MaxFFType			10	// Number of fast food types
    #define		MaxNumbInShelf		8	// Number of each food type to be on shelf
    #define		LineP				"--------------------"
    
    //////////////////////////////////////////////////////////////////////////////
    
    class FF;					// Fast Food type
    class FFS;					// Fast Food Stall
    class FFCtr;				// Fast Food checkout Counter
    class FFCus;				// Fast Food Customer
    
    struct FFAttr {
    	int		maxTime;		// Store the input maximun timing for this food type
    	double	cost;			// Cost to make this food type
    	double	profit;			// Profit earned from selling this food type
    };
    
    //////////////////////////////////////////////////////////////////////////////
    
    class FF {		// fast food class
    	private:
    		int				timeTag;	// Record time lapse of this food
    		static FFAttr	attr[MaxFFType];// Store the food type input
    	public:
    		inline FF() {  timeTag = 0;  };
    		inline ~FF() { };
    		inline void resetTimeTag() {  timeTag = 0;  };
    		inline int getTimeTag(void) const {	return timeTag;	};
    		inline void increTimeTag(void) {  timeTag++;  }
    		inline bool timeUp(void) const {  return (timeTag>MaxTime)?true:false;  }
    		bool setFFAttr(const int, const FFAttr); // store input in attr
    		bool getFFAttr(int, FFAttr &) const;	// retrieve value from attr
    		double r_cost(int i);
    		double r_profit(int i);
    };
    
    class FFCus {	// fast food customer class
    	private:
    		char	name;		// name of this customer
    		int		numbOfOrders;	// number of ordered items recorded in "orders"
    		int		orders[MaxFFType];	// record this customer orders
    	public:
    		FFCus();
    		inline ~FFCus() {};
    		inline void setName(const char &n) {  name = n;  };
    		inline char getName(void) const {  return name;  };
    		inline void setNumbOfOrders(const int n) {  numbOfOrders = n;  };
    		inline int getNumbOfOrders() const { return numbOfOrders;  };
    		void setOrder(const int, const int *);	// store input into "numbOfOrders" and "orders"
    		void getOrder(int &, int *) const;	// retrieve value from "numbOfOrders" and "orders"
    		int r_orders(int j);
    		void decreaseorders(int i);
    		void setindivorders(int j, int orders);
    };
    
    class FFCtr {	// fast food counter class
    	private:
    		bool		inOperation;	// "true": open; "false": close
    		int			efficiency;		// number of items this counter can check out in 1 minute
    	public:
    		FFCtr() {  inOperation = true; efficiency = 1;  };
    		~FFCtr() {};
    		inline void setOp(const bool &i) {	inOperation = i;	};
    		inline bool open() const {	return inOperation;	};
    		inline void setEff(const int &e) {	efficiency = e;	};
    		inline int getEff() const { return efficiency; };
    		void display(ofstream& outfile);	// display the counter and its operator
    };
    
    class FFS {		// fast food stall class
    	private:
    		FFCtr		ctr[MaxCtr];	// an array of 6 counters
    		FFCus		queue[MaxCus];	// an array of to take in at most 20 customers
    		FF			shelf[MaxFFType][MaxNumbInShelf];	// a 2D array to store food
    		int			numbOfCus;		// number of customer in queue
    		int			activeCtr;		// number of counters that are open
    		int			curTime;		// keep track of current time in minute
    		FFCus counter_queue[MaxCus];
    		int cust_queue;
    		double total_loss;
    		double total_sales;
    		int total_eff;
     		int longest_itempos[MaxFFType];
    		bool counteroccupied[MaxCtr];
    
    	public:
    		FFS();
    		~FFS() {};
    		inline bool queueEmpty() const {  return (numbOfCus<=0)?true:false;  };
    		void readCtrInfo(ifstream &);	// read input of counter informaiton
    		bool readFoodInfo(ifstream &);	// read input of food information
    		double r_sales();
    	    double r_loss();
    	    int r_totalcust();
     		int readmin(ifstream& infile);
    		bool readcustinfo(ifstream& infile);
    		void incrementTimeTag();
    		void movecust(int i);
    		void shift_queue();
    		void setqueue();
    		int findoldestfood(int i);
    		void oldestfoodtype(int i);
    		void arrangequeue();
     		void update();
    		void display(int min, ofstream& outfile);
    		void closedstall_loss();
    };
    
    double FF::r_cost(int i)
    {
    	return FF::attr[i].cost;
    }
    
    double FF::r_profit(int i)
    {
    	return FF::attr[i].profit;
    }
    
    FFCus::FFCus()
    {
    	int i; 
    	numbOfOrders = 0;
    	name = NULL;
    	for (i = 0 ; i < MaxFFType ; i++)
    		orders[i] = 0;
    }
    
    FFS::FFS()
    {	
    	int i;
    	activeCtr = MaxCtr; 
    	numbOfCus = curTime = 0;  
    	for (i = 0 ; i < MaxFFType ; i++)
    		longest_itempos[i] = 0;
    	for (i = 0 ; i < MaxCtr ; i++)
    		counteroccupied[i] = false;
    	total_loss = 0;
    	total_sales = 0;
    	total_eff = 0;
    }
    
    int FFCus::r_orders(int j)
    {
    	return FFCus::orders[j];
    }
    
    void FFCus::setindivorders(int j, int orders)
    {
    	FFCus::orders[j] = orders;
    }
    
    void FFCus::decreaseorders(int i)
    {
    	FFCus::orders[i]--;
    	FFCus::numbOfOrders--;
    }
    
    double FFS::r_sales()
    {
    	return FFS::total_sales;
    }
    
    double FFS::r_loss()
    {
    	return FFS::total_loss;
    }
    
    int FFS::r_totalcust()
    {
    	return FFS::numbOfCus;
    }
    
    int FFS::readmin(ifstream& infile)
    {
    	int minute = 0;
    	infile >> minute;
    	return minute;
    }
    
    bool FFS::readcustinfo(ifstream& infile)
    {
    	char c, name;
    	int i, item = 0, no_orders = 0, no_items = 0, total_items;
    	int o[MaxFFType];
    	infile >> c;
    	if (c == '*')
    		return false;
    	if (isalpha(c))
    		infile.putback(c);
    	else
    		return false;
    	for (i = 0 ; i < MaxFFType ; i++)
       	o[i] = 0;
    	while (infile >> c && isalpha(c))
    	{
    		name = c;
    		infile >> no_orders;
    		for (i = 0 ; i < no_orders ; i++)
    		{
    			infile >> c >> item >> no_items;
    			o[item-1] = no_items;
    			total_items += no_items;
    		}
    		if (FFS::numbOfCus < MaxCus)
    		{
    			queue[FFS::cust_queue].setName(name);
    			queue[FFS::cust_queue].setOrder(total_items, o);
    			FFS::numbOfCus++;
    			FFS::cust_queue++;
    		}
    	}
    	return true;
    }
    
    void FFS::incrementTimeTag()
    {
    	int i, j;
    	for (i = 0 ; i < MaxFFType ; i++)
    	{
    		for (j = 0 ; j < MaxNumbInShelf ; j++)
    		{
    			shelf[i][j].increTimeTag();
    			if (shelf[i][j].timeUp())
    			{
    				shelf[i][j].resetTimeTag();
    				FFS::total_loss += shelf[0][0].r_cost(i);
    			}
    		}
    	}
    }
    
    void FFS::movecust(int i)
    {
    	int j;
    	counter_queue[i].setName(queue[0].getName());
    	counter_queue[i].setNumbOfOrders(queue[0].getNumbOfOrders());
    	for (j = 0 ; j < MaxFFType ; j++)
    		counter_queue[i].setindivorders(j, queue[0].r_orders(j));
    }
    
    void FFS::shift_queue()
    {
    	int i, j;
    	for (i = 1 ; i < FFS::cust_queue + 1 ; i++)
    	{
    		queue[i-1].setName(queue[i].getName());
    		queue[i-1].setNumbOfOrders(queue[i].getNumbOfOrders());
    		for (j = 0 ; j < MaxFFType ; j++)
    			queue[i-1].setindivorders(j, queue[i].r_orders(j));
    	}
    }
    
    void FFS::setqueue()
    {
    	int i, j;
    	for (i = MaxCus - 1 ; i < FFS::cust_queue - 1 ; i--)
    	{
    		queue[i].setName(NULL);
    		queue[i].setNumbOfOrders(0);
    		for (j = 0 ; j < MaxFFType ; j++)
    			queue[i].setindivorders(j, 0);
    	}
    }
    
    int FFS::findoldestfood(int i)
    {
    	int longest_time = -1, j;
    	for (j = 0 ; j < MaxNumbInShelf ; j++)
    	{
    		if (shelf[i][j].getTimeTag() > longest_time)
    		{
    			longest_time = shelf[i][j].getTimeTag();
    			FFS::longest_itempos[i] = j;
    		}
    	}
    	return longest_time;
    }
    
    void FFS::oldestfoodtype(int i)
    {
    	int j, longest_item = 0, longest_timesofar = 0, longest_time[MaxFFType] = {0};
    	for (j = 2 ; j < MaxFFType ; j++)
    	{
    		if (counter_queue[i].r_orders(j) != 0)
    			longest_time[j] = FFS::findoldestfood(j);
    	}
    	for (j = 2 ; j < MaxFFType ; j++)
    	{
    		if (longest_time[j] > longest_timesofar)
    		{
    			longest_timesofar = longest_time[j];
    			longest_item = j;
    		}
    	}
    	shelf[longest_item][FFS::longest_itempos[longest_item]].resetTimeTag();
    	counter_queue[i].decreaseorders(longest_item);
    	FFS::total_sales += shelf[0][0].r_profit(longest_item);
    	for (j = 2 ; j < MaxFFType ; j++)
    		FFS::longest_itempos[j] = 0;
    }
    
    void FFS::arrangequeue()
    {
    	int i, j = 0, maxeff, maxcounter;
    	while (FFS::cust_queue > 0 && j < FFS::activeCtr)
    	{
     	  	maxeff = 0;
     		maxcounter = -1;
     		for (i = 0 ; i < MaxCtr ; i++)
     		{
     			if (ctr[i].open() && !FFS::counteroccupied[i])
     			{
     				if (ctr[i].getEff() > maxeff)
     				{
     					maxcounter = i;
     					maxeff = ctr[i].getEff();
     				}
     			}
     		}
     		if (maxcounter != -1)
     		{
     			FFS::movecust(maxcounter);
     			FFS::counteroccupied[maxcounter] = true;
     			FFS::cust_queue--;
     			FFS::shift_queue();
     			FFS::setqueue();
     		}
          j++;
     	}
    }
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0
    (Part 2 of header file "ffs3.h")

    Code:
    void FFS::update()
    {
    	int i, j, cookeditems = 0, non_cookeditems = 0;
    	int temp_eff[MaxCtr];
    	for (j = 0 ; j < MaxCtr ; j++)
    	{
       		temp_eff[j] = ctr[j].getEff();
       		FFS::total_eff += temp_eff[i];
    	}
    	while (FFS::total_eff != 0)
    	{
    		if (FFS::numbOfCus == 0)
    			break;
    		FFS::total_eff = 0;
    		for (i = 0 ; i < MaxCtr ; i++)
    		{
    			cookeditems = 0;
    	   		non_cookeditems = 0;
    			if (ctr[i].open())
    			{
    			for (j = 2 ; j < MaxFFType ; j++)
    			{
    				if (counter_queue[i].r_orders(j) != 0)
    					cookeditems += counter_queue[i].r_orders(j);
    			}
    			if (cookeditems > 0)
    			{
    				if (cookeditems <= temp_eff[i])
    				{
    					for (j = 0 ; j < cookeditems ; j++)
    					{
    						FFS::oldestfoodtype(i);
    						temp_eff[i]--;
    					}
    				}
    				else
    				if (cookeditems > temp_eff[i])
    				{
    					cookeditems = temp_eff[i];
    					for (j = 0 ; j < cookeditems ; j++)
    					{
    						FFS::oldestfoodtype(i);
    						temp_eff[i]--;
    					}
    				}
    			}
    			if (temp_eff[i] > 0 && counter_queue[i].getNumbOfOrders() > 0)
    			{
    				for (j = 0 ; j < 2 ; j++)
    				{
    					if (counter_queue[i].r_orders(j) != 0)
    						non_cookeditems += counter_queue[i].r_orders(j);
    				}
    				if (non_cookeditems > 0)
    				{
    					if (non_cookeditems <= temp_eff[i])
    					{
    						for (j = 0 ; j < non_cookeditems ; j++)
    						{
    							if (counter_queue[i].r_orders(0) > 0)
    							{
    								counter_queue[i].decreaseorders(0);
                				    temp_eff[i]--;
                   				    FFS::total_sales += shelf[0][0].r_profit(0);
    							}
    							else
    							{
    								counter_queue[i].decreaseorders(1);
    								temp_eff[i]--;
                					FFS::total_sales += shelf[0][0].r_profit(1);
    							}
    						}
    					}
          				else
             			if (non_cookeditems > temp_eff[i])
                		{
                			non_cookeditems = temp_eff[i];
    	   					for (j = 0 ; j < non_cookeditems ; j++)
    						{
          				 		if (counter_queue[i].r_orders(0) > 0)
             					{
    								counter_queue[i].decreaseorders(0);
                   					temp_eff[i]--;
                      				FFS::total_sales += shelf[0][0].r_profit(0);
    							}
       							else
          						{
             		      			counter_queue[i].decreaseorders(1);
                					temp_eff[i]--;
                   					FFS::total_sales += shelf[0][0].r_profit(1);
      	               			}
    						}
       					}
    				}
    			}
         		if (counter_queue[i].getNumbOfOrders() == 0)
    			{
       	   			FFS::counteroccupied[i] = false;
          			FFS::numbOfCus--;
    			}
    			FFS::total_eff += temp_eff[i];
    		}
    	}
    }
    
    void FFS::display(int min, ofstream& outfile)
    {
    	int i;
    	for (i = 0 ; i < MaxCtr ; i++)
    		ctr[i].display(outfile);
    	outfile << "\tMinute " << min;
    	outfile << endl;
    	for (i = 0 ; i < MaxCtr ; i++)
    	{
       		if (ctr[i].open())
    			outfile << "      " << counter_queue[i].getName();
    		else
          		outfile << "       ";
    	}
    	outfile << endl;
    	outfile << "\t\t\t\t\t\t" << FFS::numbOfCus << " customers" << endl;
    	outfile << "    | ";
    	if (FFS::cust_queue >= 1)
       		outfile << queue[0].getName();        // draw the start of the queue
    	else
       		outfile << " ";
    	outfile << " |------------------";
    	outfile << endl;
    	outfile << "    \\ ";
    	if (queue[1].getName() != NULL)
    	{
       		for (i = 1 ; i < FFS::cust_queue ; i++)
    	   		outfile << queue[i].getName();
    	}
    	outfile << endl;
    	outfile << "     \\---------------------";
    	outfile << endl;
    }
    
    void FFS::closedstall_loss()
    {
    	int i, j;
    	for (i = 0 ; i < MaxFFType ; i++)
    	{
    		for (j = 0 ; j < MaxNumbInShelf ; j++)
    		{
    			FFS::total_loss += shelf[0][0].r_cost(i);
    		}
    	}
    }
    
    #endif
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0
    (Source file "foodstall_C.cpp")

    Code:
    #include	"ffs3.h"
    
    FFAttr	FF::attr[MaxFFType];
    
    bool FF::setFFAttr(const int i, const FFAttr a)
    {
    	if (i >= MaxFFType) return false;
    	attr[i].maxTime = a.maxTime;
    	attr[i].cost = a.cost;
    	attr[i].profit = a.profit;
    	return true;
    }
    
    bool FF::getFFAttr(int i, FFAttr &a) const
    {
    	if (i >= MaxFFType) return false;
    	a.maxTime = attr[i].maxTime;
    	a.cost = attr[i].cost;
    	a.profit = attr[i].profit;
    	return true;
    }
    		
    ////////////////////////////////////////////////////////////////////////////////
    
    void FFCus::setOrder(const int n, const int *o)
    {
    	numbOfOrders = n;
    	for (int i=0; i < MaxFFType; i++) 
    		orders[i] = o[i];
    }
    
    void FFCus::getOrder(int &n, int *o) const
    {
    	n = numbOfOrders;
    	for (int i=0; i < MaxFFType; i++) 
    		o[i] = orders[i];
    }
    
    ////////////////////////////////////////////////////////////////////////////////
    
    void FFCtr::display(ofstream& outfile)
    {
    	outfile << "\\_";
    	if (inOperation) 
    		outfile << "@";
    	else 
    		outfile << "_";
    	outfile << "_/";
    }
    
    ////////////////////////////////////////////////////////////////////////////////
    
    void FFS::readCtrInfo(ifstream &infile)
    {
    	int	operational, eff, i;
    
    	for (activeCtr=i=0; i<MaxCtr; i++) {
    		in >> operational >> eff;
    		if (operational > 0) {
    			ctr[i].setOp(true);
    			activeCtr++;
    		}
    		else ctr[i].setOp(false);
    		ctr[i].setEff(eff);
    	}
    }
    
    bool FFS::readFoodInfo(ifstream &in)
    {
    char		c;
    int			n;
    FFAttr		a;
    
    	for (;;) {
    		in >> c;
    		if (isdigit(c)) {
    			in.putback(c);
    			break;
    		}
    		in >> n;
    		if (n > MaxFFType) return false;
    		in >> a.maxTime >> a.cost >> a.profit;
    		shelf[0][0].setFFAttr(n-1, a);
    	}
    	return true;
    }
    
    /////////////////////////////////////////////////////////////////
    
    main()
    {
    	ifstream infile("ffs3.txt", ios::in);
    	FFS	stall;
    	int minute = 0, temp_time = 0;
    
    	if (!infile) {
    		cerr << "Cannot open ffs3.txt!\n";
    		return 0;
    	}
    	stall.readCtrInfo(infile);
    	stall.readFoodInfo(infile);
        stall.display(0, outfile);
    	while (!infile.eof())
        {
      		minute = stall.readmin(infile);  // read in minute
    		while (minute != temp_time)
      		{
     			temp_time++;
    			stall.incrementTimeTag();
          		if (minute == temp_time)
             		stall.readcustinfo(infile);   // read in names and items for the minute
    			stall.arrangequeue();
    			stall.display(temp_time, outfile);
    			stall.update();
       		}
    	}
    	while (stall.r_totalcust() > 0)   // output until all customers have been served
    	{
    		stall.incrementTimeTag();
    		stall.arrangequeue();
    		stall.display(temp_time + i, outfile);
    		stall.update();
    		if (stall.r_totalcust() == 0)
    			break;
    		i++;
    	}
    	stall.closedstall_loss();
    	outfile << endl;
    	outfile << "stall closed at time " << minute << " (minutes)" << endl;
    	outfile << "sale = $" << stall.r_sales() << " wasted food = $" << stall.r_loss();
    	infile.close();
    	outfile.close();
     	return 0;
    }
  8. #5
  9. *bounce*
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Delft, The Netherlands
    Posts
    514
    Rep Power
    42
    Ugh. Until you throw the files onto the web and post links, I'm not even going to try digging through all that.

    Also, you might want to read the Forum Guidelines again, or better yet, read this.
    "A poor programmer is he who blames his tools."
    http://analyser.oli.tudelft.nl/

IMN logo majestic logo threadwatch logo seochat tools logo