-
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
-
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";
}
-
>> 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.
-
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.
-
remove semicolon after the if(answer==2) and after the else