O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required