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: ...

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.