Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Delphi and Pascal
Variables, Assignment and
Types
Personality Tester
var
yournumber:integer;
begin
write( 'Please enter a number between 1 and 99: ');
readln(yournumber);
w...
Values
• A basic thing – a letter or a number
• Values have TYPES
• Integers 1, 29485
• Strings “Hello world”
• Double– fl...
Variables
• A variable has a value
mynumber
Variable names
• Can’t begin with a number
• Can’t contain spaces or other funnies
• Can’t be a keyword
– Type help() and ...
Assignment
Putting a Value ‘into’ a Variable
• myVariable := 23
• myLongVariable := “Hello how’s it going”
Sometimes writt...
Assignment quiz
• What’s the value of myVariable
myVariable := 22;
mySecondVariable := 13;
myVariable := mySecondVariable;...
Statements
• A statement is a piece of code that
Pacal can execute.
• Lots of statements make a program
Operators
• Operators ‘do things’ to operands
• The simplest operators are the math
+ addition 5+2
- subtraction 5-2
* mul...
A useful program
• Write a Fahrenheit to Celsius converter
• The formula for the conversion is: F = 1.8 * C + 32
• To make...
Challenge
• Write a script/program that allows you to
input two numbers and calculates their:
– Product
– Sum
– Difference...
Upcoming SlideShare
Loading in …5
×

Pascal names and types

926 views

Published on

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Pascal names and types

  1. 1. Delphi and Pascal Variables, Assignment and Types
  2. 2. Personality Tester var yournumber:integer; begin write( 'Please enter a number between 1 and 99: '); readln(yournumber); writeln('You entered ' , yournumber); writeln('Performing personality analysis on your number choice …'); if yournumber < 49 then writeln('You are truly inadequate') else writeln('You have delusions of grandeur'); writeln('That''s all folks'); readln; end.
  3. 3. Values • A basic thing – a letter or a number • Values have TYPES • Integers 1, 29485 • Strings “Hello world” • Double– floating point 3.14159
  4. 4. Variables • A variable has a value mynumber
  5. 5. Variable names • Can’t begin with a number • Can’t contain spaces or other funnies • Can’t be a keyword – Type help() and press return – Then type keywords in the box. • Case doesn’t matter .. But it does!
  6. 6. Assignment Putting a Value ‘into’ a Variable • myVariable := 23 • myLongVariable := “Hello how’s it going” Sometimes written with an arrow • myVariable 23 Assignment is really a sort of COPY Why?
  7. 7. Assignment quiz • What’s the value of myVariable myVariable := 22; mySecondVariable := 13; myVariable := mySecondVariable; myVariable := str(myVariable);
  8. 8. Statements • A statement is a piece of code that Pacal can execute. • Lots of statements make a program
  9. 9. Operators • Operators ‘do things’ to operands • The simplest operators are the math + addition 5+2 - subtraction 5-2 * multiplication 5*2 / division 5/2 div integer division 5 div 2 mod modulo 5 mod 2
  10. 10. A useful program • Write a Fahrenheit to Celsius converter • The formula for the conversion is: F = 1.8 * C + 32 • To make this program work you will need to do the following: Get the user input with readln(variablename); • Now you have an integer, multiply it by 1.8 and add 32 • Print the result – your answer, to the screen with writeln(variablename)
  11. 11. Challenge • Write a script/program that allows you to input two numbers and calculates their: – Product – Sum – Difference – Quotient (one number divided by the other without any remainder) – Remainder (remainder when one is divided by the other)

×