May 2002
Beginner
320 pages
6h 18m
English
The do/while loop works fine as long as you can be absolutely sure that users really ran the program with the intent of doing at least one calculation. But what if they ran the program by accident and want to stop right away?
You can use the while loop in this situation. It requires only a minor change to the main() function in Listing 9.1, as shown in Listing 9.4.
1: int main(int argc, char* argv[]) 2: { 3: SAMSErrorHandling::Initialize(); 4: *5: while (SAMSPrompt::UserWantsToContinue("Divide? ")) *6: { 7: try 8: { 9: float Dividend = GetDividend(); 10: float Divisor = GetDivisor(); 11: 12: cout << Divide(Dividend,Divisor) << endl; 13: } 14: catch (...) 15: { 16: SAMSErrorHandling::HandleNotANumberError(); ... |
Read now
Unlock full access