A Very Basic Calculator
It's been another busy time. I've had to dealt with the holiday season and the return of college. I was also doing exploration into Pygame for a project. However, I am back and ready to program. I've got a calculator to show.
With a new semester, I've got another class for programming. The professor told us we were going to start off by doing our finale project: Making a useful calculator capable of doing actions beyond what a scientific calculator can do. This is to be done in Visual Basic.
For the moment, however, we were told to make a calculator capable of simple calculations such as adding or multiplication. One of those simple calculators like the basic calculator on iPhones (when not in scientific mode).
This was a mildly difficult task. I had to learn some basics about how calculators work. The display was rather easy, as with most Visual Basic programs. Here is the code for it.
In summary, the calculator has functions for these tasks:
- Display. Changing which numbers appear on the display. This also includes clearing functions such as A, C, an CE (though thinking about it I probably didn't need to have all these), along with special numbers such as pi and e.
- One number operations. Mathematical functions that only need one inputted number, such as finding a square root or 1/x. When pressed, these will return the results.
- Two number operations. Basic functions that need two inputted numbers. This calculator currently has the ability to add, subtract, multiply, divide, and raise to a power. When pressed, these will need a second value typed in and the equal sign pressed in order to return a result.
This function can handle some errors. If you were to try to divide by 0, it would list an error instead of crash. However, there seems to be some problems with some results, such as doing 0 to some powers, that will have to be fixed later.
I did use Visual Basic's math class for this to do some operations such as getting a square root or to get numbers like pi or e. However, I won't be able to use those later on, and I will have to create my own functions for those instead of using the class.
This is the first version of a calculator I'm making. The professor now wants us to create functionality for parentheses. By the end of the semester, I'll have a fully functional calculator. Next time will probably include the improved version of this calculator. For now, stay tuned and see you next time.
Comments
Post a Comment