WEEK 2 Variables - Prompts
WEEK 2 Variables - Prompts
- To display value of variable (ex: If your grosspay is 200 — put (Display grosspay)
when you put that in it will display 200)
Using Prompts
- Use a prompt which asks user to enter specific value, use uppercase letters:
- First DECLARE your variable(age), DISPLAY prompt, INPUT
1. Declare Integer age
2. Display “What is your age?”
3. Input age
Variable Initialization
- When declaring a variable, you can optionally assign a value to it in the declaration
statement
Ex: Declare Real price = 49.95 (this assigns the value 49.95 to the variable “price”)
Uninitialized Variables
- A variable that has been declared, but not assigned any value
- Can cause errors and could assign a default value of 0
- test3 doesn’t have a set value (the score is unknown), so you won’t be able to add
all the test scores to get the average
- Use word “set” to give value to the variable (ex: Set test1 = 88.0)
- The word “real” means value has decimals
- The word “integer” means the value is a whole number without decimals
Assignments and Calculations
- An assignment statement gives a variable a value (Ex: Set price = 20)
- Modulus gives the remainder (10/3 = 3 it doesn’t show 3.3, it gives whole number,
10%3 = 1)
- Exponent (2^3)
- Division gives the quotient (10/3 = 3 it doesn’t show 3.3, it gives whole number)
PROBLEM 1
You can set a whole number to a “real amount” and “integer” but cannot set a decimal
number into integer, only into a “real amount” (If you have a whole number such as 3 and
put “Set Real amount” it will display 3.0, if you put “Set Integer amount” it will display 3)
(If you have a decimal such as 3.7 and try to set it as an integer amount, it will cause an
error. It has to be set as a real amount)
Constants
- A value that cannot be changed
- Constant is written in all uppercase letters (ex: Constant Real INTEREST_RATE =
0.069) (You use Constant instead of Declare)
- If you notice a variable is not being affected by other variables, declare the variable
as a constant
- Constant variables must have a value, cannot be left blank