Thread: What do these errors mean?

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    52

    What do these errors mean?

    Code:
    printf("\n\nWhat would you like to see?\n");
    It says error: expected ')' before ';' token

    Code:
      )
        case (2):


    error: expected ';' before 'case'
    Code:
     case(4):
    error: case label not within a switch statement|
    Code:
    default:  printf("\n%d is not a valid choice.\n", choice1);
    error: 'default' label not within a switch statement

    All of these appear fine to me, but the build did not happen and in the book it is the way it appears on-screen. So, anything?

    Thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,304
    They are syntax errors, and they mean exactly what the error messages say. The actual mistake may correspond directly to the error message, but sometimes a mistake changes the "shape" of the code such that the compiler detects a syntax error that appears a little further away from the mistake made, but nonetheless the error message and line number gives you a starting point to start searching for the mistake. (This could be the case for the first error you listed.)

    Quote Originally Posted by solidusMGS
    All of these appear fine to me, but the build did not happen and in the book it is the way it appears on-screen. So, anything?
    That just means that you need to look more carefully: they are not fine at all.

    If you have really looked very carefully and it is true that the code is exactly the same as in your book, then either the book is rubbish, or the compiler that you're using is rubbish. But it's more likely due to typo errors by you.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,617
    Post the whole code, not just single line snippets.

    The errors are because you've generally messed up the balance of ( ) and brace pairs.
    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.

  4. #4
    Registered User
    Join Date
    Dec 2019
    Posts
    52
    Quote Originally Posted by Salem View Post
    Post the whole code, not just single line snippets.

    The errors are because you've generally messed up the balance of ( ) and brace pairs.
    It's a lot of code and I'm scared no one would look at it, but here goes:

    Code:
    #include<stdio.h>#include<stdlib.h>
    
    
    main()
    
    
    {
    
    
    int choice1;
    int choice2;
    
    
    printf("What do you want to see?\n");
    printf("1.  The 1980s\n");
    printf("2.  The 1990s\n");
    printf("3.  The 2000s\n");
    printf("4.  quit\n");
    
    
    do
    
    
    {
    
    
    printf("Enter your choice:  ");
    scanf("  %d", &choice1);
    switch (choice1)
    {
        case(1):
    (
    
    
        printf("\n\nWhat would you like to see?\n");
        printf("1.  baseball\n");
        printf("2.  The movies?\n");
        printf("3.  US Presidents\n");
        printf("4.  Quit\n");
    
    
        printf("Enter your choice:  ");
        scanf("  %d", &choice2);
    
    
        if (choice2 == 1)
        {
            printf("\n\nWorld Series Champions  ");
            printf("of the 1980s:\n");
            printf(" 1980:  Philies\n");
            printf(" 1981:  Dodgers\n");
            printf("  1982:  dodgers\n");
            printf("  1983:  Cardinals\n");
            printf("  1984:  Tigers\n");
            printf("  1985:  Tigers\n");
            printf("  1986:  Royals\n");
            printf("  1987:  Royals\n");
            printf("  1988:  Twins\n");
            printf("  1988  As\n");
            printf(" \n\n\n");
            break;
            } else if (choice2 == 2)
            {
                printf("\n\nOscar Winning movies in the 1980s:\n");
                printf("1980:  Ordinary people\n");
                printf("1981:  Chariots of Fire\n");
                printf("1982:  Gandi\n");
                printf("1983:  Terms of Endearment\n");
                printf("1984:  Amadeus\n");
                printf("1985:  Out of Africa\n");
                printf("1986:  POop\n");
                printf("1987:  The Last Emperor\n");
                printf("1988:  Rain man\n");
                printf("1989:  Driving Miss Daisy\n");
                printf("\n\n\n");
                break;
                }else if (choice2 ==3)
    
    
                {
                printf("\n\nUS Presidents in the 1980s:\n");
                printf("1980:  Jimmy Carter\n");
                printf("1984:  Reagan\n");
                printf("1988:  George Bush\n");
                printf("\n\n\n");
                break;
    
    
                }else if (choice2==4)
    
    
                {
                exit(1);
                }else
                {
    
    
                printf("Sorry, not a valid choice!\n");
                break;
                }
    
    
    
    
        )
        case (2):
        {
            printf("\n\nWhat would you like to see?\n");
            printf("1.  Baseball\n");
            printf("2. The movies\n");
            printf("3.  US Presidents\n");
            printf("4.  Quit\n");
    
    
            printf("Enter your choice:  ");
            scanf("  %d", &choice2);
    
    
            if (choice2 == 1)
    
    
            {
                printf("\n\nWorld Series Champions of ");
                printf("the 1990s:\n");
                printf("1990:  reds\n");
                printf("1991:  reds\n");
                printf("1992:  twins\n");
                printf("1993:  Blue Jays\n");
                printf("1994:  blue jays\n");
                printf("1995:  Twins\n");
                printf("1996:  Braves\n");
                printf("1997:  Braves\n");
                printf("1998:  Marlins\n");
                printf("1999:  Yankees\n");
                printf("\n\n\n");
                break;
    
    
    
    
            }else if (choice2 == 2)
            {
                printf("\n\nOscar Winning Movies in ");
                printf("the 1990s:\n");
                printf("1990:  Dancing with Wolves\n");
                printf("1991:  Silence\n");
                printf("1992: unforgiven\n");
                printf("1993:  Schnidlers list\n");
                printf("1994:  Enlgish\n");
                printf("1995: Titanic\n");
                printf("1996: Shakespears in love\n");
                printf("1997:  American beauty\n");
                printf("\n\n\n");
                break;
                }else if (choice2 == 3 )
                {
                    printf("\n\nUS Presidents in the 1990s\n");
                    printf("1992: Bush\n");
                    printf("1996: Clinton\n");
                    printf("\n\n\n");
                    break;
            } else if (choice2 == 4)
            {
    
    
            exit(1);
            } else
            {
                printf("sorry, no good\n");
                }
    
    
            }
    
    
     case (3):
     {
    
    
        printf("\n\nWhat would you like to see?\n");
        printf("1. baseball\n");
        printf("2. movies\n");
        printf("3. US presidents\n");
        printf("4. Quit\n");
    
    
        printf("Enter your choice:  ");
        scanf("  %d",  &choice2);
    
    
        if (choice2 ==1)
    
    
        {
    
    
            printf("\n\nWorld series champs of ");
            printf("the 2000s:\n");
            printf("2000:  Yankees\n");
            printf("2001:  Diambonbacks\n");
            printf("2002:  Angels\n");
            printf("2003:  Angels\n");
            printf("2004:  marlins\n");
            printf("2005:  White sox\n");
            printf("2006:  Cardinals\n");
            printf("2007:  Red Sox\n");
            printf("2008:  Red sox\n");
            printf("2009:  Yankees\n");
            printf("\n\n\n");
            break;
    
    
    
    
    
    
    
    
        }else if (choice2 == 2)
        {   printf("\nOscar winning movies in ");
            printf("the 2000s\n");
            printf("2000:  Gladiator\n");
            printf("2001:  MNind\n");
            printf("2002:  Chicago\n");
            printf("2003:  Lotr\n");
            printf("2004:  lotr\n");
            printf("2005:  million dollar baby\n");
            printf("2006:  crash\n");
            printf("2007:  Crash\n");
            printf("2008:  Hurt locker\n");
            printf("2009:  slumdog\n");
    
    
            printf("\n\n\n");
            break;
    
    
            } else if (choice2 ==3)
            {
                printf("\n\nUS presidnets in the 2000s:\n");
                printf("2000:  Bill Clinton\n");
                printf("2001-2008:  George Bush\n");
                printf("2009:  Obama\n");
                printf("\n\n\n");
                break;
    
    
                }else if (choice 2 ==4)
                (
                exit(1);
                )else
                {
                printf("Sorry, not a valid choice.\n");
                break;
                }
    
    
    
    
    
    
    
    
        }
    
    
    
    
    
    
    
    
    
    
    }
     case(4):
        exit(1);
        default:  printf("\n%d is not a valid choice.\n", choice1);
        printf("Try again.\n");
        break;
    
    
    }  while (( choice1 <1) || ( choice1> 4));
    return 0;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }
    Errors are on lines :

    28, 90 232, 234

  5. #5
    Registered User
    Join Date
    Dec 2019
    Posts
    52
    Lines 35, 105, 276, 278. Sorry, about that.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,617
    Part of the problem is your indentation is lousy, so you've no idea what lines up with what.

    Part of the problem is you have NO functions in your program, just a bloated main with hundreds of lines of code.

    Start with
    Code:
    void the_1980s ( ) {
    }
    void the_1990s ( ) {
    }
    void the_2000s ( ) {
    }
    
    int main ( ) {
        printf("Enter your choice:  ");
        scanf("  %d", &choice1);
        switch (choice1) {
            case 1: the_1980s(); break;
            case 2: the_1990s(); break;
            case 3: the_2000s(); break;
        }
    }
    Part of the problem is you have NO data. You should have arrays of data for things like presidents_1980s and movies_1990s.

    Part of the problem is you seem to have just typed the whole lot in, only to find out that it doesn't compile.

    Code:
        case (1):
          (printf("\n\nWhat would you like to see?\n");
    That thing before the printf should be a brace, not a bracket.

    A development process
    Remember, compile early and often, and fix things as soon as you see them.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help in some errors!!!!!
    By AMA1989 in forum C++ Programming
    Replies: 2
    Last Post: 04-26-2011, 06:41 AM
  2. have some errors, need some help
    By Seiro in forum C Programming
    Replies: 7
    Last Post: 04-19-2006, 12:06 PM
  3. BS Errors
    By bikr692002 in forum C++ Programming
    Replies: 11
    Last Post: 04-05-2006, 01:34 PM
  4. Errors!
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 12-15-2005, 08:59 PM
  5. errors.. errrors.. more errors
    By Klinerr1 in forum C++ Programming
    Replies: 17
    Last Post: 07-23-2002, 08:43 PM

Tags for this Thread