OUR EXPERT
QUICK TIP
QUICK TIP
VARIABLE SCOPE
QUICK TIP
DATA TYPES
Andrew Smith is a software developer for NHS England. He enjoys video gaming and started coding in C/C++ in 1997 on a Borland C++ for DOS compiler.
You can find the full source to this project at https:// github.com/ asmith1979/ lxf302/.
There is a file in the folder of the chess program and of the OpenGL test program called build.txt, which contains the build commands that can be copied and pasted into command line.
Variables in a C/C++ program can be declared locally, globally or across different files. In this project, variables are mainly declared both globally and locally, which determines how code within the program can access them. Usually, global variables are declared near the top of a C/C++ program, just after the library files have been included, so they can be accessed by functions in the code. For example, the function processGameControllerOutput() uses variables such as actionRightTaken, actionLeftTaken, actionUpTaken and actionDownTaken. These variables are accessible to any function in the program because they are declared globally. A variable would be a local variable if it was declared inside a function itself, which results in only that function being able to access the variables. In main.cpp there is a function called drawMoveToSquare that, at the start of the function, declares two local variables of type float that can only be accessed by the code within that function and nowhere else. Variables or values may also be passed into functions as what is known as arguments or parameters, which can be accessed by the code within the function. An example of this is a function in main.cpp called showWord that takes in two integer values and one string value. This is then used by the code in the function to manipulate text and position.
Instead of scrolling through code, it may be better to use the editor’s search facility to go directly where you want to go in the code.
In C/C++, data types can be applied to variables and functions (and methods in C++). The main data types in C/C++ are: Integers (int) Decimal values (float) String (string or char *)
OUR EXPERT
Andrew Smith is a software developer for NHS England. He enjoys video gaming and started coding in C/C++ in 1997 on a Borland C++ for DOS compiler.