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:
  1. 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.
  2. 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.
  3. 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.
The calculator works by inputting a number and pressing one of the function keys. If the function is a two number operation, the currently displayed value is saved to a temporary variable. After a second value is inputted and the equal sign is pressed. The value of what is currently displayed will be taken. Both the first and current value will be put through a function that will figure out which operator is to be used, and will calculate the results.

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

Popular posts from this blog

Version 2:The Not-So Barebones Clicker

A Prime Factorization Algorithm that Uses a Text File

Aesthetico Ultimate Designer - A Python Turtle Program