Final projects
As stated earlier this chapter, will have two final projects. To start exploring numerical programming, we’re going to look at the final challenge from the previous chapter and program the perimeter of a rectangle.
Final project 1 – programming the perimeter of a rectangle
The perimeter of a rectangle can be described with the following equation:
This will be a relatively simple equation to program. However, before looking at the code, take a moment and try to solve the problem yourself if you haven’t already.
Solution
Our first step is to declare our variables. Since this equation is based around three variables, length
, width
, and prim
, to keep this program as flexible as possible, the data types should be of the REAL
type and can be declared with the following code:
PROGRAM PLC_PRG VAR prim : REAL; width : REAL := 5; length : REAL :...