Thread: Sorry, forgot to log in when I posted this message....

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    Thumbs up Sorry, forgot to log in when I posted this message....

    I just wrote this tiny program just to try out my newly gained knowledge on text files, but I don't think its anything to do with the text file part which is causing the error:
    38: parse error before `else'

    Here is the code which I am having problems with...

    cout << "\nWould you like to save your document?[1]Yes [2].No";
    int answer;
    cin >> answer;

    if (answer = 2);
    {
    remove (FileName.c_str());
    }
    else;
    {
    cout << "You may now exit";
    }


    }


    Thanks
    -Chris

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    6

    Thumbs up FIXED THE PROBLEM

    you have this

    if (answer = 2) {

    .
    .
    .

    }

    else;

    { .... }

    i tried this

    if (answer == 2) ...... else ...

    hence> you dont need the brackets, you only have one statement after the if ()!

    else does not need a semi-colon either

    and the if () does not use a semi-colon either

    only use brackets for multiple statements like so

    if (x == 1) {
    temp = 4;
    x = 5;
    }

    but for one its

    if (x == 1) temp = 4;

    hope this helps

    UncleG

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    6

    Talking MISSED THIS OUT

    You have an extra } at the end of the code !

    sorry i missed that!

    UncleG

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  2. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  3. fprintf works in one function but not in the other.
    By smegly in forum C Programming
    Replies: 11
    Last Post: 05-25-2004, 03:30 PM
  4. My log file player; Hit the brick wall
    By Twig in forum C Programming
    Replies: 6
    Last Post: 07-27-2002, 05:35 PM
  5. Sending CChildView a Message :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 04-06-2002, 03:00 PM