There will often be times when we want to save the result of a Boolean expression, arithmetical expression, or string value so that we can use it later in our program.  For example we might want to remember a user’s preferences so we can refer to them later, or store the result of a complex arithmetical expression so the computer is only laboured to work it out once.  We do this with things called variables.  A variable is a name given to some place in the computer’s memory where we can store a value.  We can then use the name of the variable in an expression, or change the value of the variable.  There are different types of variables for the different types of information we can store:

int  (short for integer) stores a numerical value
bool  (short for boolean) stores a boolean value
string  stores a string value

The first step is to tell the compiler the type of variable, what we want to call it, and optionally, the value we want it to have.  This is called ‘declaring’ the variable. For example:

string a declares a variable of type string, which we have called 'a', and have not given a value yet
bool b = false declares a variable of type bool, which we have called 'b', and have given the value false
int c = 2 + 3 declares a variable of type int, which we have called 'c', and have given the value of the result of the arithmetical expression 2 + 3

Only once we have declared a variable, can we obtain or change its value.  For example:

c = 10; changes the value of the already declared variable 'c' to 10

If we attempted to change the value of the variable c without declaring it first, the compiler would tell us we have made an error.

The program already given to you below uses the function:

readString()

This function allows you to type something into the output window, and when you press enter, it will assign the string that you typed to the given variable and carry on with the program.

Tasks: