Adding the Percent Key to a Calculator Project

Like a lot of teachers I have use the four-function calculator project as a way to introduce various programming concepts to my students. Just figuring out how to keep track of 10 number key buttons can be a little challenging of course. But generally by the time I use this project I am most interested in a good project for using a stack. Simple calculators are good for that.

Many students once they implement the basic add, subtract, multiply and divide functions start looking for additional functions to add. This is something I have always encouraged. Square root is often the first "extra" feature they add because it can be done simply with a built-in function. Occasionally I have had students add parentheses. That's a but more advanced and shows a lot of understanding of both math and CS concepts.

Recently I ran across a post by Raymond Chen that explains how the calculator key in the Windows calculator works. Its the same way it works in most standard four-function calculators one can buy. The surprising thing to me is that it works differently, though better, then I thought it did. I very seldom use that key but now that I know how it works I might just use it in the future. The post also suggests that adding the percent key to a calculator project might just be a lot more useful than I would have thought.

Raymond's post describes the algorithms and logic behind them in simple easy to understand terms. It's really useful that way. You can see not only how the function works in practice but the algorithms involved and why they are set up the way that they are.

There are also a lot of comments to his post that are interesting in their own right. In fact I can see them as a basis for a classroom discussion about the percent key, about how features for calculators and other programs are designed, and the whole question of why is it that some people never seem to see the same value in a feature that the creator of the feature do?

Comments (0)

Skip to main content