Presentation is loading. Please wait.

Presentation is loading. Please wait.

CRE Programming Club Class 2 (Import JJZ543 and Practice Your Typing!)

Similar presentations


Presentation on theme: "CRE Programming Club Class 2 (Import JJZ543 and Practice Your Typing!)"— Presentation transcript:

1 CRE Programming Club Class 2 (Import JJZ543 and Practice Your Typing!)

2 Constants and Variables What’s a variable? What’s a constant?

3 Constant or Variable? How sleepy you are? How many hands you have? The color of your eyes? How big the school is? What color shoes you’re wearing? How many eyes you have? The color of your hair? How many sides a triangle has? How hungry you are? The position of the sun in the sky? The temperature outside?

4 Variables Variables vary (change), and constants are constantly the same. In the world of programming, there are values in your program that need to change all the time, and there are values that will stay the same. For the most part in Small Basic, you’ll be using variables.

5 Variables How do we create a variable in Small Basic? Well, we just give it a name and set it equal to something. A = 20 This is kind of like getting a box, writing “A” on the outside, and putting the number 20 inside of it. If you come along later and say, “Hey, I’d like to use what’s in A, you’re going to get 20.” At this point in the program, A = 20.

6 Variables Let’s test that out by adding the following line afterwards: TextWindow.WriteLine(“A is “ + A) This command will write out the current value of A. What happens if we put the following after it? A = 21 TextWindow.WriteLine(“A is “ + A)

7

8

9 How Programs Run Small Basic programs will read in one line at a time, and execute (run) the code on that line. Program run one line at a time. Programs can jump around if they need to, but we’ll look at that later. At the first TextWindow.writeLine() instruction, A is 20. On the next, A is 21.

10 Variable Names The name for a variable can be almost any mix of letters, digits, and the character _ (called "underscore"); the only exception is that it cannot begin with a digit. Small Basic doesn't worry about UPPER and lower case. The names AREA, area and Area all refer to one and the same variable.

11 What Can a Variable Store? So what can a variable store? Well, with Small Basic, one of two things. We already know it can store a number. For those of you working with fractions and decimals, variables can store any number, including those with decimals. So, 40 and a half would be written as 40.5.

12 Variables Can Also Store Words! Hmmm… how do computers handle words? Well, kind of like what you did as a baby with building blocks. Remember that computers are dumb and they really, really love codes. Turns out the computer has a code number for each letter, a code number for a space, a code number for a questions mark, and, well… a code number for pretty much everything on your keyboard.

13 What Can a Variable Store? When it wants to use words, it just strings the letters and symbols together like the building blocks of a baby. And, when it’s done, it adds on a special code that says, “Okay, this is the end of the it!” So, we know about numbers, but what are these words or sets of words or symbols or whatever called?

14 Strings! Let’s write a string and assign it to a variable. A = “Hello There” Note that a string is always surrounded by double quotes. What if we write: A = Hello There

15 You Can All Sorts of Things With Variables A = “Hello There” A = 12.34 + 45.67 A = 1 + 9 * 4 A = B A = A + 1 A = (B * C) / D A = Math.PI A = Math.PI * R * R A = currentArea - 1 A = “Hello “ + “There” A = “12” + “34” A = “Hello “ + 12

16 Adding Strings and Numbers What happens if we add two numbers together? What happens if we add a number to a string? A = “Hello” A = A + “ There ” A = A + 12 Try it!

17 Import VXD019 We’re missing a line that defines the variable kelvin. The formula for converting a temperature to Kelvin is to simply add 273.15 to the Celsius temperature. Add the line that is needed so that the program runs without causing an error!

18 Import RTW796-5 This is your first homework assignment. Create three variables that are the radius, circumference, and area of a circle, given the diameter. Use the TextWindow.WriteLine() command to print out the results. Questions? Send me an email at reckstei@gmail.com. reckstei@gmail.com

19 Next Time.... We’re going to learn about objects!


Download ppt "CRE Programming Club Class 2 (Import JJZ543 and Practice Your Typing!)"

Similar presentations


Ads by Google