In my calculator, there're numbers 0 to 9 and other signs buttons. In this post, I will like to focus on how I develop my code regarding those arithmetic operation.
Each arithmetic operation consists of two operands, one operator and one result. Since we have only one text box, we definitely one temporary variable to store the number because the text box can hold only one number at one time. So, let's break down our process of adding numbers. It'll be like this :
1) Enter first number
2) Choose the type of operation
3) Enter second number
4) Choose = sign to get the result
As I mentioned, we need a temporary variable to store the first number, and we need to write a method to perform the arithmetic operation. So, after we enter the first number and choose an operation type, we need to clear out the first number so that when you enter a second number, the text box will start from scratch.
So, the code will look like this :

Now, what happens when you hit =. It's supposed to grab two numbers and return a result. And here's what the code looks like.

No comments:
Post a Comment