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

The Calculator Tape in the Accumulator

Returning to the broader picture, Listing 12.2 shows the Accumulate() function in main.cpp with some minor changes that enable it to use the tape.

Listing 12.2. Using the Tape in Accumulate()
 1: float Accumulate 2: (const char theOperator,const float theOperand) 3: { 4: static float myAccumulator = 0; // Set at program start 5: 6: switch (theOperator) 7: { 8: case '+': 9: myAccumulator = myAccumulator + theOperand; 10: break; 11: 12: case '-': 13: myAccumulator = myAccumulator - theOperand; 14: break; 15: 16: case '*': 17: myAccumulator = myAccumulator * theOperand; 18: break; 19: 20: case '/': 21: myAccumulator = myAccumulator / theOperand; 22: break; 23: *24: case '?': *25: break; 26: 27: default: 28: ...

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