Thread: Synax errors with my else statements, help appreciated.

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    4

    Synax errors with my else statements, help appreciated.

    Hey there. I seem to be having some syntax errors with this part of my code. I am new to this and I cannot figure out what is wrong. I am not sure if you need the whole code or just this part, but any help would be much appreciated.


    Code:
        else {
        while(y<size) {
        while(x<size) {
            if((y=0) && (y=size-1)); {
            printf("*");
            }
            
            else {
            if((x=0) && (x=size-1)); {
            printf("*");
            }
            }
            
            else {
            printf(" ");
            x++;
            y++;
            }
        }
    }
    }

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    One problem I see is that you use the assignment operator in your if statements instead of the equality operator == .

    Edit: also on line 8, you have else { if... } followed by another else. Use else if { ... } instead.
    Last edited by Subsonics; 02-07-2012 at 02:36 PM.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Oh, thanks for noticing that. It probably is an issue, but that is not the one that I am currently frustrated with. I went and changed to the equality operators, but I still got syntax errors with the else statements.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    And you have semi-colons after the ifs, making them pointless.

    And here is what your program looks like properly formatted:

    Code:
    else {
    	while(y<size) {
    		while(x<size) {
    			if((y=0) && (y=size-1)); {
    				printf("*");
    			} else {
    				if((x=0) && (x=size-1)); {
    					printf("*");
    				}
    			} else {
    				printf(" ");
    				x++;
    				y++;
    			}
    		}
    	}
    }
    Maybe that will help you see the issue.
    Last edited by rags_to_riches; 02-07-2012 at 02:40 PM.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Oh. Thanks rags. The semi-colons were the main issues with the last two syntax errors. But the very first syntax error with the else still remains.

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    You two else statements.

  7. #7
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Well this is how far I have gotten with all your help. It is just syntax errors with the {'s. Lines 6 and 7, as well as the second to last }. How would I fix this? Thanks.

    Code:
        else {
            while(y<size) {
                while(x<size) {
                    if((y=0) == (y=size-1)) {
                        printf("*");
                    } else if { 
                        ((x=0) == (x=size-1)) {
                            printf("*");    
                    } else {
                        if((x!=0) == (x!=size-1)){
                        printf(" ");
                        x++;
                        y++;
                        }
                    }
                }
            }
        }
    }
    Last edited by heyitsmeehd; 02-07-2012 at 03:32 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with if and if-else statements
    By cb0ardpr0gr^mm3r in forum C Programming
    Replies: 2
    Last Post: 11-18-2010, 11:13 PM
  2. Need help, would be very appreciated.
    By DK12 in forum C Programming
    Replies: 16
    Last Post: 07-28-2009, 04:54 PM
  3. Seemingly correct printf statements bringing up errors
    By hpteenagewizkid in forum C Programming
    Replies: 9
    Last Post: 11-08-2006, 12:13 PM
  4. Linker Errors, Help Appreciated
    By burntheart in forum Windows Programming
    Replies: 3
    Last Post: 03-27-2006, 07:13 AM
  5. Why do I get these errors in the If statements?
    By Drew in forum C++ Programming
    Replies: 4
    Last Post: 09-10-2003, 08:52 PM