My program

This is a discussion on My program within the C++ Programming forums, part of the General Programming Boards category; I just wrote this tiny program just to try out my newly gained knowledge on text files, but I don't ...

  1. #1
    Unregistered
    Guest

    Thumbs up My program

    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
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Code:
    //need the double equal sign
    if (answer == 2)
    { 
    //not sure what this part is
    remove (FileName.c_str()); 
    } 
    //no terminating semi colon after else
    else
    { 
    cout << "You may now exit"; 
    }
    Last edited by Witch_King; 08-27-2001 at 01:14 AM.
    I compile code with:
    Visual Studio.NET beta2

  3. #3
    Registered User Hoegje's Avatar
    Join Date
    Aug 2001
    Posts
    4

    Thumbs up

    >> if (answer = 2);

    this should be "if (answer == 2)" without the quotes.

    Because you put a semicolon after this statement the compiler doesn't expect an else statement.

  4. #4
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    No take out the semi colon. I didn't put it there. I just copied and pasted the code and didn't see it there.
    I compile code with:
    Visual Studio.NET beta2

  5. #5
    Unregistered
    Guest
    remove semicolon after the if(answer==2) and after the else

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21