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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.