Generalizing the Calculator

You have been writing a lot of code to support performing division. Now you are ready to take a major step and make this simple program into a full-blown calculator. And the switch statement will be an important part of that change.

Let's start with the main() function, shown in Listing 11.1.

Listing 11.1. main() as a Real Calculator
 1: int main(int argc, char* argv[]) 2: { 3: SAMSErrorHandling::Initialize(); 4: 5: do 6: { 7: try 8: { *9: char Operator = GetOperator(); *10: float Operand = GetOperand(); 11: *12: cout << Accumulate(Operator,Operand) << endl; 13: } *14: catch (runtime_error RuntimeError) *15: { *16: SAMSErrorHandling::HandleRuntimeError (RuntimeError); *17: } 18: catch (...) 19: { 20: SAMSErrorHandling::HandleNotANumberError(); ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.