Download presentation
Presentation is loading. Please wait.
1
CHAPTER FOUR VARIABLES AND CONSTANTS
COMPUTER MATHEMATICS CHAPTER FOUR VARIABLES AND CONSTANTS
2
USING VARIABLES Variable – memory location that stores a value
Variables must be declared with a DIM statement DIM – includes identifier and data type Identifier – name of variables; how it is referred to within the program Data Type – kind of value to store
3
USING VARIABLES Example: DIM dblRadius As Double
dblRadius – variable or identifier; begins with dbl to indicate data type Double – numeric data type that possibly contains decimals Reserves a space in the computer’s memory for a value Numeric variables are given the value of zero initially
4
VARIABLE ASSIGNMENT Variables are given values through assignment statements Identifier (variable name) is on the left of the = and the value on the right Example: dblRadius = 12.3 The value of 12.3 is stored in the memory location named dblRadius You cannot reverse an assignment statement: = dblRadius ‘Error!
5
VARIABLE ASSIGNMENT An expression can be used on the right side of an assignment statement Example: dblArea = 3.14 * dblRadius ^ 2 The result of the expression will be stored in the memory location named dblArea Variables can be used wherever a value is used
6
VARIABLE ASSIGNMENT Variables can only store one value at a time
Example: DIM dblY As Double dblY = 5 dblY = 10.5 The value of 10.5 is stored in dblY because it was the last value assigned
7
VARIABLE ASSIGNMENT Expression on the right side of the = and then the resulting value is given to the variable on the left side. Example: DIM dblAdd As Double dblAdd = 5 dblAdd =dblAdd + 10 The value of 15 is stored in the memory location dblAdd
8
LAB TIME Review # 1 Review #2
9
In review 1 part (b), what would be the final value of dblResult if the statement dblResult = 5 was removed? Write a comparison of the readability of the Circle application from Chapter Three Review #8 to the Circle Area application of Chapter Four Review #2.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.