# How to design calculator in labview : tutorial 27

In this tutorial I will guide you to design a VI that will help you to do simple mathematical operations. In simple words I will guide you to design a simple calculator that will allow you to add, subtract, multiply and divide two numbers. It will first ask you to enter two digits you want to use as operators, after that you will have to select the operation and the VI will return the output the operation applied to the operands you entered. At the end of the tutorial you are provided with an exercise to do it by yourself, and in the next tutorials I will assume that you have done those exercises and I will not explain the concept regarding them

## Design calculator in labview example

• Lets’ now move to the designing part as create a VI as we have discussed in tutorial 1 and save it for future use as we have been doing in all previous tutorials. From the function palette on the block diagram select numeric and then select add as shown in the figure below,

• At the input side of this block two nodes are present right click on that node a dropdown menu will appear from that menu select create and then select control this will create an input control for the input of the operands as shown in the figure below,

Figure 2: Creating control

• Do the same for the second input of the add block too. Now, at the output of this block one node is present, click right on that node and from the drop down menu select create and then select indicator, this will create an indicator to display the output as shown in the figure below,

Figure 3: Creating indicator

• The complete block diagram for adding two numbers is shown in the figure below,

• We will need an enumerated control here to select the case for operation. On the front panel click right and from the control palette select rings and enums and then select enum control as shown in the figure below,

Figure 5: Enum control placement

• On this block click right and from the drop down menu select edit items as shown in the figure below,

Figure 6: Edit items window

• this will display a window and we have also discussed this in previous tutorials, create 4 items in the enum control window named as add, subtract, multiply and divide as shown in the figure below, and click ok

Figure 7: Adding items in the enum control

• Now come to the cases part. We will need to select the case for each operation i.e. add subtract etc depending upon the enum controls’ input Therefore we will need a case structure as we have already used in previous tutorials. From the function palette select structures and then select Case structure as shown in the figure below,

Figure 8:Case structure placement

• Place the add block on the block diagram inside the case structure and all other indicators and controls outside it as shown in the figure below,

Figure 9: Case structure

• Now, connect the enum control we created previously o the case selector node of the case structure as shown in the figure below,

Figure 10: Case selector node

• The case for this operation will be automatically selected as subtracts. Right click on the case structure boundary and from the drop down menu select make this case add as shown in the figure below,

• Now change the selector label to subtract and from the function palette select numeric and then select subtract as shown in the figure below,

Figure 12: Subtract block placement

• Connect the input side of this block to the input nodes of the case structure and the output side to the output node of the case structure as shown in the figure below,

Figure 13: Subtract case

• By default case selector have only two case, but in our case we need four cases so we have to add two more cases. Click right on the boundary of the case structure and from the dropdown menu select Add case after as shown in the figure below,

• Now change the selector label to multiply and from the function palette select numeric and then select multiply as shown in the figure below,

Figure 15: Multiply block placement

• Connect the input side of this block to the input nodes of the case structure and the output side to the output node of the case structure as shown in the figure below,

Figure 16: Multiply case

• Now change the selector label to divide and from the function palette select numeric and then select divide as shown in the figure below,

Figure 17: Divide block placement

• Connect the input side of this block to the input nodes of the case structure and the output side to the output node of the case structure as shown in the figure below,

Figure 18: Divide case

• On the front panel enter two values to the input control and from the enum control select the operation you want to perform, and run the VI. The figures below shows the output of every operation for same operands