Thread: getting parse error

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    17

    getting parse error

    in function PrimeFactor
    parse error before '0'

    Code:
    int PrimeFactor()
    {
      int y;
      int fact;
      int r,i;
      int num1, num2, gpf; 
      enum { FALSE, true } Prime;
      y=GetNum(num1);
      
    		
    	Prime = TRUE;
    	gpf = floor(sqrt(y));
    
                    for(fact=2; fact <= gpf; fact++)
    
                while( y % fact == 0)
     /*i believe error is here but wuts wrong*/
    	{
    
                    if(Prime)
                        {
                        printf("%d = %d", y, fact);
                        Prime = FALSE;
    	}
                    else
    	{
    	printf(" * %d", fact);
    	y = y/fact;
    	}
    	if(Prime)
    	printf("%d is a prime number.", y);
    
                else 
    		if(y!=1)
                                    {
    		printf(" * %d", y);
    		printf("\n\n");
    		}
    	else
    
    	printf("The Prime Factors for this number are\n");
    	printf("%d = ", y);	
    	for (i=2; i <=y; i++)
    	{
    	     while( y % i == 0)
    		{
    		 y = y / i;
    	                 printf(" * %d",i);
    		}
    	}
    				
    	}
          }		
    printf("\n\n");		 
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Here are a few items:

    *1*

    enum { FALSE, true } Prime;
    Prime = TRUE;

    The two words are not the same.


    *2*
    Code:
    for(fact=2; fact <= gpf; fact++)
                while( y % fact == 0)
    Here you have nested loops. You may want this, but if you don't, I thought I'd just point it out.

    On a side note, you should really use one common indentation. Either just use tabs, or just use spaces. Don't mix them, because it makes your code hard to read when you transport it from one editor to another. (Or into a form such as this.)

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM