Quote (Minkomonster @ May 10 2014 06:27pm)
Your solution fails if the user inputs the wrong number nCallStack times. It will keep adding a new frame to the stack over and over until it rejects it with a stack overflow. It's an edgecase, seeing as how they would have to incorrectly enter the number 1000+ times. But Murphy's law mandates that eventually one user will come along dumb enough to trigger that edge case. You don;t ahve that probably with a simple loop.
Hmm, I see
So this:
Code
void writeProverb(int number)
{
while(number != 1 && number != 2) {
if(number == 1){
cout << "Now is the time for all good men to come to the aid of their party.";}
else if(number == 2){
cout << "Now is the time for all good men to come to the aid for their country.";}
else if(number != 1 && number != 2){
cout << "Input error. Try again: " << endl; // If input is not 1 or 2.
cin >> number;
}
}
}
Could loop indefinitely, until the CPU uses power, as long as the user keeps entering wrong values?