Thread: primary expression before else

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    3

    primary expression before else

    I used the if and else to make a basic program to tell someone happy birthday but I keep getting an error saying primary expression before else

    here is my source code

    Code:
    // Birthday program
    
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    
    using namespace std;
    
    int main()
    {
        int a;
        cout << "Is it your Birthday today? Type 1 for yes and 2 for no. /t";
        cin >> a;
        if (a==1);
        {
        cout << "Happy Birthday I hope today is really good for you!";
    }
        else;
       {
        cout << "Then open this on your birthday instead";
    }
        system("PAUSE");
        return 0;
    }

  2. #2
    Registered User MrMatt027's Avatar
    Join Date
    Nov 2010
    Location
    USA, Florida
    Posts
    21
    Take away the ; in
    Code:
     if (a==1);
    and also in
    Code:
    else;
    That's what I did in CodeBlocks and it's working fine.
    Last edited by MrMatt027; 12-03-2010 at 11:04 PM.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Code:
    if (a==1);
        {
        cout << "Happy Birthday I hope today is really good for you!";
    }
        else;
    The semi-colons I've highlighted should not be there.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    3
    sorry that is the older one before I removed the semi colons I am using dev compiler does that make a difference

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    3
    Nevermind Thank you for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. expected primary expression
    By lilhawk2892 in forum C++ Programming
    Replies: 10
    Last Post: 11-22-2007, 07:50 PM
  2. expected primary expression before "." token
    By melodious in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2007, 04:39 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 09:15 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM