Hello and welcome to our community! Is this your first visit?
Register
Results 1 to 3 of 3
  1. #1
    Regular Member
    Join Date
    Jul 2008
    Location
    Why are you reading this pedofile?
    Posts
    248

    Yet another C++ compile error

    SOrry, I'm prolly a pain in the @$$, but I have yet another problem. I am trying to make a small AI program, you know, just for practice, who knows what I could make out of it. The errors I get are as follows...:
    --------------------
    In function `int main()':
    Line 27 expected primary-expression before "else"
    Line 27 expected `;' before "else"
    Line 29 expected primary-expression before "else"
    Line 29 expected `;' before "else"
    --------------------

    I don't understand what is wrong. I have the semi-colons in their correct places, I have my brackets set, everything is fine.

    Here is the code:

    Code:
    #include <iostream>
    #include <cstring>
    
    #define NL '\n'
    #define pi '3.14159'
    
    using namespace std;
    
    int main()
    {
        int x = 0, y = 55;
        char mood, reason, activity;
        char yn[3];
        char input[0];
        
        cout<<"Hello, how are you?\n";
        cin>>mood;
        cout<<"Why are you "<<mood<<"?/n";
        cin>>reason;
        cout<<"I guess that's a good reason. What did you do today?\n";
        cin>>activity;
        cout<<activity<<"? Did you have fun doing that?\n";
        cin.getline ( yn, 3, '\n' );
        cin.ignore();
        if ( !strcmp ( input, yn )) {
             cout<<"That's good, at least you did something you enjoyed. I did nothing but sit here all day. You want to help me have fun?\n ";
             else
             cout<<"Oh that's too bad. I sat here all day. Want to help me have fun?\n ";
             else If
             cout<<"I'm sorry, I don't understand what you said. Oh well, I did nothing but sit here all day. You want to help me have some fun?\n";
             }
        cin>>yn;
        cout<<"Oh, really? I guess I am going to have to kill you now...\n";
        cin.get();
    }

  2. #2
    Obsessed Veteran Adam's Avatar



    Join Date
    Nov 2004
    Location
    UK / England
    Posts
    17,271

    Re: Yet another C++ compile error

    Check your brackets and conditions. I can cleary see you're missing a bracket and have rogue "else If" statement.

    It must be else if(EXPRESSION). Else ifs must have an expression to create a valid condition.

    The order

    if(Expression){}
    else if(Expression){}
    else{}

  3. #3
    Regular Member
    Join Date
    Jul 2008
    Location
    Why are you reading this pedofile?
    Posts
    248

    Re: Yet another C++ compile error

    AH, I see now. Thanks adam, it works perfectly now. I might wanna keep this thread open in case into any other problems


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •