Using Variables Variables form a very important aspect of every programming language. Variables are memory locations in which we can store a value. We.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

7.1Variable Notation.
1.2 Apply order of operations
Exponents, Parentheses, and the Order of Operations.
Sending, Receiving and Processing Messages NQC Tutorial pp
2. Textual user interface NQC (Not quite C)  C-like programs translated into CRX-bytecode  Composed of: 1.Global variables 2.Task blocks 3.Inline functions.
LEGO Mindstorms RIS 2.0 Programming: NQC Code B.A. Juliano and R.S. Renner September 2004 California State University, Chico Intelligent Systems Laboratory.
Inline Functions Sometimes you need the same piece of code at multiple places in your task. Inline functions are copied at each place they are used. In.
Tasks An NQC program consists of at most 10 tasks. Each task has a name. One task must have the name main, and this task will be executed. The other tasks.
1 MATERI PENDUKUNG OPERATOR Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Repeating Blocks of Code (updated 9/20/05 7:35pm) Reference NQC Tutorial pp 9-12.
Preprocessor Directives (last modified 9/19/05 2:47pm) Statements beginning with # are directives to the preprocessor. –They DO NOT end with ; –Before.
Copyright 2013, 2009, 2005, 2002 Pearson, Education, Inc.
Chapter 1 Section 3 Copyright © 2011 Pearson Education, Inc.
EXAMPLE 1 Following Order of Operations Music You buy a used guitar for $50. You then pay $10 for each of five guitar lessons. The total cost can be found.
Section 3Chapter 1. 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Objectives Exponents, Roots, and Order of Operations Use exponents. Find.
4.3 Matrices and Determinants Algebra 2. Learning Targets: Evaluate the determinant of a 3 x 3 matrix, and Find the area of a triangle given the coordinates.
 When adding radical expressions, you want to have the same root and radicand.  With the same root and radicand, you can add the coefficients and.
Notes October 8, 2012 Unit 3 Linear Expressions and Equations Expressions Linear Expressions and Equations.
Evaluating a Variable Expression To evaluate a variable expression:
Order of Operations - rules for arithmetic and algebra that describe what sequence to follow to evaluate an expression involving more than one operation.
Variables and Algebraic Expressions 1-3. Vocabulary Variable- a letter represents a number that can vary. Constant- a number that does not change. Algebraic.
Divide. Evaluate power – 3 = – 3 EXAMPLE – 3 = 3 2 – – 3 = 6 – 3 Multiply. Evaluate expressions Multiply and divide from.
1. Substitute a number for the variable. 2. Perform all operations. 3. Simplify the result. Steps to EVALUATE AN EXPRESSION…
1-2 Order of Operations and Evaluating Expressions.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Unit 2: Integers Unit Review. Multiplying Integers The product of two integers with the same sign is a positive. Eg: (+6) x (+4) = +24; (-18) x (-3) =
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
Lesson 4-2 Warm-Up. Lesson 4-2 Warm-Up Exponents (4-2) What is a a “base” number, “exponent” , and “power”? exponent: a shorthand way to show repeated.
Why we complete the square  We have learned how to factor quadratic expressions to solve.  Many quadratic equations contain expressions that cannot be.
Holt CA Course 1 Evaluating Algebraic Expressions 1-5 AF1.2 Write and evaluate an algebraic expression for a given situation, using up to three variables.
The Order of Operations Chapter Evaluate inside grouping symbols ( ), { }, [ ], | |, √ (square root), ─ (fraction bar) 2.Evaluate exponents 3.Multiply.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
Notes 2.1 Order of Operations PEMDAS If an expression has only numbers and symbols, it is a numerical expression. If it has a variable it is a variable.
1-2 Order of Operations Objective: Use the order of operations to evaluate expressions.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
Combining Like Terms and the Distributive Property Objectives: Students will be able to explain the difference between algebraic equations and expressions.
Learn to evaluate algebraic expressions.. Vocabulary variable constant algebraic expression evaluate.
Chapter 10 Polynomials and Factoring. Entry Task 04/09/2013.
Windows Programming Lecture 03. Pointers and Arrays.
ORDER OF OPERATIONS. 1.Perform any operations with grouping symbols. 2.Simplify powers. 3.Multiply and divide in order from left to right. 4.Add and subtract.
Powers and Exponents.
1 Chapter Chapter 2 The Whole Numbers.
The actor and director Ron Howard was born in 1954.
Click the mouse button or press the Space Bar to display the answers.
Subtracting Integers #41.
CSE 220 – C Programming Expressions.
2 Chapter Chapter 2 Integers and Introduction to Variables.
So, to simplify an expression using order of operations, you should:
2-2 Writing and Solving Equations with Variables on Both Sides
Assignment statement:
1 Introduction to Algebra: Integers.
Arithmetic operations & assignment statement
Introduction to Algebra
Algebra 1 Section 2.3 Subtract real numbers
Radical Operations Unit 4-3.
Multiplying and Dividing Powers
ORDER OF OPERATIONS BEMDAS. 1. Brackets - ( ) or [ ]
With Assignment Operator
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Rational Numbers & Equations
You replace it with its simplest name
Chapter 3: Lesson 3 Order of Operations
Making Equivalent Expressions By Combining Like Terms
Chapter 4-2 Power and Exponents
Preprocessor Directives
Do Now Simplify. 1. 5(7) – (18 – 11)  (40 – 35) (12 – 4)
Do Now Evaluate each algebraic expression for y = 3. 3y + y y
Evaluating Expressions
Presentation transcript:

Using Variables Variables form a very important aspect of every programming language. Variables are memory locations in which we can store a value. We can use that value at different places and we can change it. Suppose we want to write a program that makes our robot drive in a series of squares of increasing size. This can be achieved by increasing the value of MOVE_TIME after each square. But how can we do this? MOVE_TIME is a constant and constants cannot be changed. We need a variable instead. Variables can easily be defined in NQC. You can have 32 of these, and you can give each of them a separate name.

Making Squares #define TURN_TIME 85 int move_time; // define a variable task main() { move_time = 20; // set the initial value repeat(50) { OnFwd(OUT_A+OUT_C); Wait(move_time); // forward motion increases OnRev(OUT_C); Wait(TURN_TIME); } Off(OUT_A+OUT_C); }

Assignment Variable = expression; x = 7; x = x + 3; tar = x*3 + tar; Expressions are evaluated from with the following precedence. * / top level + - second level Thus, x = 3+4*2 ==> 11 x = (3+4)*2 ==> 14 x = 2+4/2 ==> 4 x = (2+4)/2 ==> 3 For operators at the same level of precedence the order is left to right.

bar = 1+ Random(4); // ramdom number between 1 and 5 X = SENSOR_1 +2; //adds 2 to the value of sensor on port 1 Some other variants of the assignment statement (borrowed from C) bar += 7; // adds 7 to bar same as bar=bar+7 bar -= 2; // subtracts 2 from bar same as bar=bar-7 bar *= 4; // multiplies bar by 4 same as bar=4*bar

Spiraling Squares #define TURN_TIME 85 int move_time; // define a variable task main() { move_time = 20; // set the initial value repeat(50) { OnFwd(OUT_A+OUT_C); Wait(move_time); // forward motion increases OnRev(OUT_C); Wait(TURN_TIME); move_time += 5; // increase the variable } Off(OUT_A+OUT_C); }