Exercise+3

**Exercise 3** **Sequential Structures: //Assignment Statements//**

Think of variables as if they were boxes. There are only a certain amount of boxes available to the computer -- the amount is determined by the amount of memory (RAM) the computer possesses. A declaration statement tells the computer that first there is a box; it has a name; we might put things in it; and the variable type is the sort of thing we're going to put in it if we decide to do so. If we wish to put something in the box we have to use an assignment statement.

The statement **x := 3 * 8** is an example of an assignment statement. It is called that because it assigns **values** to **variables**.

The way to think of an assignment statement is ** "__x becomes _"__ **__ or **"x is assigned the value of** **__** .__ Assignment statements have a definite form which they must follow **identifier :=** **value**

Constants are like variables except that their values cannot be changed. They are used to assign a value to a space in RAM which will **never** change during the execution of the programme. i.e., **const PI := 3.1459**. (PI becomes 3.1459)

Note that ** constants are always declared and assigned in the same statement. ** It's like telling the computer that "you can shut the box because we're never, ever, ever going to put anything else in it". This saves the computer time and let's your program run faster.

**Task:** Complete the following exercises in your notebook Identify which assignment statements are correct (OK). Correct those which are incorrect.

Remember: Only one variable may be on the left side of an assignment statement. You are assigning the result of the calculation to that variable's memory location.
 * **Assignment Statement** || **Correction** ||
 * money:= $45.00 ||  ||
 * r * 6:= 2 * x + 8 ||  ||
 * 4/3 +5*t :=pay ||  ||
 * put:= 4 + 6 * 3/2 ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">gross pay := rate * hours ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">net_pay := grosspay - deductions ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">variable := VARIABLE * 2 ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">7th_number := 12 ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">number6 := number +12 ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">counter := counter +1 ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">pi * r * *2 ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">area_circle := pi (radius **2)** ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">student% := total_marks/4 ||  ||
 * <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">%area_rectangle := length * width ||  ||

<span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">The percent sign % tells the computer to ignore everything to the right of it -- this is used for internal documentation (instructions you want to leave for people who have to read your program... like me)**