rough draft of code for CalcStack
runs without throwing errors but gives wrong answer
completed CalcStack code