if you type "N" then "Y", that is when the bugs show up |
This is because you're calling
main() recursively. Do NOT call main recursively. Looping constructs exist for what you're trying to do.
If you type "N", then you call main again. Within
that call to main, you type in "Y", then zero gets returned up the stack. This does not end the program.
Then, back in main (i.e. the the first entry into main), the code that's "within" the else clause gets called. I say "within" because the code after your else clause is equivalent to this:
1 2 3 4 5 6 7 8
|
else
{
(sAnswer != "Y" || sAnswer != "y" || sAnswer != "N" || sAnswer != "n");
}
cout << "Please type Y for yes or N for no.\n";
sAnswer.erase(0,10000);
main();
|
i.e. in your else, that boolean expression is evaluated and its result is discarded. The braces after your else simply serve as a scope and nothing more.
The else clause does not require an expression like the if or else if. You should remove the
(sAnswer != "Y" || sAnswer != "y" || sAnswer != "N" || sAnswer != "n");
from your else clause.
And always be careful about trailing semi-colons after else clauses. They make it so the else clause does nothing. Compilers should warn about that though.