Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using variable Variables are used to store values.

Similar presentations


Presentation on theme: "Using variable Variables are used to store values."— Presentation transcript:

1 Using variable Variables are used to store values

2 x : = 7 x is the variable. x is assigned the value of 7 7 Think of x as being a box with a 7 inside it

3 number : = 7.4 The variable called number is assigned the value of 7.4 7.4 The name of this box is number

4 student: = “B. Orr” The variable called student is assigned the value of “B. Orr” B. Orr The name of this box is student

5 Variables in Turing Must be declared Three main types – int for integer (a number with no decimals) – real for any number that might have a decimal – string for any variable that might have letters in it Ex. var n: int var radius:real var schoolname:string

6 What type of variable would you use? 1.To store the price of a milk shake? 2.To store the number of students in a class 3.To store the name of a horse? 4.To store the average of five numbers? 5.To store the number of songs you have in iTunes?

7 Using the get statement (1) We’ve seen the put statement for output The get statement is for input Example … ask the user for their age var age:int put "Please tell me your age“.. get age put "You are ", age, " years old"

8 Using the get statement (2) We’ve seen the put statement for output The get statement is for input Example … ask the user for their average mark var mark:real put “What is your average?" get mark put "Your mark is ",mark

9 Using the get statement (3) We’ve seen the put statement for output The get statement is for input Example … ask the user for their name and address var nme, add:string put “What is your name?" get nme put “What is your address?" get add put “Your name is “, nme,” and you live at “,add

10 Sample problem Ask the user for their name, their age and their favourite TV show. Print the information on a clear screen. var nme, tvshow:string var ageLint put “What is your name?”.. get nme put “Tell me your favourite TV show”.. get tvshow put “How old are you?” get age put “Thanks “, nme, “ you are “, age, “ years old and you like to watch “,tvshow


Download ppt "Using variable Variables are used to store values."

Similar presentations


Ads by Google