\b;Exercise
This exercise is very similar to the previous one. The bot must move exactly in the same way, but when writing the program, you must use a new concept that is extremely important in programming: \l;variables\u cbot\var;.
We saw that all the pads are at a distance form each other of 20 meters. And all the rotations performed consist in 90 degree angles. Instead of rewriting the same values over and over again in the program, we can store them in a variable: 

Instead of:
\c;\s;	move(20);
\s;	turn(90);
\s;	move(20);
\s;	turn(-90);
\s;	...
\n;
We write :
\c;\s;	dist = 20;
\s;	dir = 90;
\s;	move(dist);
\s;	turn(dir);
\s;	move(dist);
\s;	turn(-dir);
\s;	...
\n;
\b;Variables
A \l;variable\u cbot\var; is composed of three elements: 
1) The name
2) The type of the content
3) The content

\t;The name
Use the name to refer to a variable. For example, instead of writing \c;move(20);\n;, write \c;move(dist);\n;: "dist" is the name of the variable. You can choose almost any name for a variable, for example \c;dist\n;, \c;dir\n;, \c;p2\n;, \c;a\n;, \c;x\n;, \c;nothing_2_grab\n;, etc.

\t;The type
The type of a variable determines what kind of information the variable can contain. According to the type, a variable can contain a whole number, a real number, a character string, the coordinates of a point, etc. Here is a list with the most common variable types: 
  o  \c;\l;int\u cbot\int;\n; for a whole number (12, -500, etc.)
  o  \c;\l;float\u cbot\float;\n; for a real number (3.14, 0.2, -99.98, etc.)
  o  \c;\l;string\u cbot\string;\n; for a character string ("Hello!", "Nothing to grab", etc.)
  o  \c;\l;point\u cbot\point;\n; for the x,y,z-coordinates of a point in space
  o  \c;\l;object\u cbot\object;\n; for the information about an object (bot, building, etc.) 

\t;The content
The content of a variable can be a number, a string, coordinates, etc., according to the type of the variable. The content of a variable can change many times during the execution of a program. 

Before you can use a variable, you have to declare it. For example, before you can use the two variables \c;dist\n; and \c;dir\n;, you must declare them with the following lines: 
\c;
\s;	float  dist;
\s;	float  dir;
\n;
Now you can use the two variables. To put the value 20 into \c;dist\n; and 90 into \c;dir\n;, write:
\c;
\s;	dist = 20;
\s;	dir = 90;
\n;
Now you can move and turn the bot with the instructions \c;\l;move\u cbot\move;\n; and \c;\l;turn\n;\u cbot\turn;:
\c;
\s;	move(dist);
\s;	turn(dir);
\n;
You can also use a whole \l;mathematical expression\u cbot\expr; instead of just the variable:
\c;
\s;	move(dist+100);
\s;	turn(-dir);
\n;
The latter instruction will be needed to turn the bot right. 

Now, rewrite the program of the previous exercise, but use a variable for the distance and another variable for the angle of the rotation. 

\t;See also
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
