Thread: problems with "else"

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    35

    problems with "else"

    Im trying to write a simple program about the peter piper tongue twister but I cant seem to get the else part of the program working.

    Code:
    #include <stdio.h>
    
    int main (int argo, char *argv[]) {
    
       int numberOfPeppers;
       numberOfPeppers = 0;
    
       printf ("peter piper picked a peck of pickled peppers.\n");
       printf ("how many pickled peppers did peter piper pick?\n");
       scanf ("%d", &numberOfPeppers);
       printf ("peter picked %d peppers\n", numberOfPeppers);
    
       if (numberOfPeppers == 0); {
       printf ("none? i guess he is lazy then.");
    
       } else {
       printf ("wtf is a 'peck of pickled peppers' anyway?");
    
       }
    
       return 0;
    
    }
    code blocks tells me the error is on the } else { line

    error: expected primary-expression before "else"
    error: expected `;' before "else"

    ive tried comparing it to similar codes and trying to find faults with no success.
    so can someone please explain the error?

    thx

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    if (numberOfPeppers == 0);
    Remove the extra ;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I'm glad to see literature rearing it's ugly head here again.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    35
    thanks salem, works fine now

    Quote Originally Posted by MK27 View Post
    I'm glad to see literature rearing it's ugly head here again.
    come again?

  5. #5
    Registered User BuzzBuzz's Avatar
    Join Date
    Feb 2009
    Posts
    89
    FYI -

    Peck:
    A unit of dry volume or capacity in the U.S. Customary System equal to 8 quarts or approximately 537.6 cubic inches.

    That's a lot of pickled peppers!

    Kind of ruins the rhyme though

    Although those figures could be fun to use in working out how many pecks of pickled peppers the user has inputed in real terms.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM