May 2002
Beginner
320 pages
6h 18m
English
The big danger in the earlier example is that, because you've put the same bool expression in two places, you will cause an accident if you do not make or keep the two expressions identical. This could lead to a serious and hard-to-solve problem in your program during repair or enhancement. You can use a bool variable to avoid it, as shown in Listing 10.3.
1: bool UserWantsToContinueYOrN (const char *theThingWeAreDoing) 2: { 3: char DoneCharacter; *4: bool InvalidCharacterWasEntered = false; 5: 6: do 7: { 8: cout << 9: endl << 10: theThingWeAreDoing << 11: " - Press \"n\" and \"Enter\" to stop: "; 12: 13: cin >> DoneCharacter; 14: ... |
Read now
Unlock full access