if statement tracing
DESCRIPTION
If Statement Tracing. Worksheet Solutions. Question #1. If num = 10 Then score = score + 20 End If **no change to form. Question #2. If sum 0 Then score = score – 10 End If **no change to form. Question #3. If score >= 10 Then txtNumber.text = score Else - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/1.jpg)
If Statement Tracing
Worksheet Solutions
![Page 2: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/2.jpg)
Question #1
If num = 10 Then
score = score + 20
End If
**no change to form
Price Num Score Sum
2.50 10 142 0
162
![Page 3: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/3.jpg)
Question #2
If sum <> 0 Then
score = score – 10
End If
**no change to form
![Page 4: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/4.jpg)
Question #3
If score >= 10 Then
txtNumber.text = score
Else
txtNumber.text = num
num = 0
End If
![Page 5: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/5.jpg)
Question #4
If score < 100 Then
txtNumber.text = score
lblAnswer.caption = “you lose”
Else
txtNumber.text = num
lblAnswer.caption = “you win”
End If
![Page 6: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/6.jpg)
Question #5
If price > 10 Then
price = price * 1.15
txtNumber.text = price
lblAnswer.caption = “15% tax”
Else
price = price * 0.5
txtNumber.text = price
lblAnswer.caption = “50% off”
End If
Price Num Score Sum
2.50 10 142 0
1.25
![Page 7: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/7.jpg)
Question #6
If price < 10 Then
sum = sum + score
txtNumber.text = sum
Else
sum = sum + num
txtNumber.text = sum
End If
Price Num Score Sum
2.50 10 142 0
142
![Page 8: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/8.jpg)
Question #7
If price >= 5 Then
num = num – 1
txtNumber.text = price
ElseIf price >= 100 Then
price = price + 1
txtNumber.text = price
End If
• No change in variables or form
![Page 9: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/9.jpg)
Question #8
If price < 2 Then lblAnswer.caption = “Cheap Price”ElseIf price > 3 Then lblAnswer.caption = “Adjusted Price”Else lblAnswer.caption = “Bad Price”End If
![Page 10: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/10.jpg)
Question #9
price = price \ 10
If price > 2 Then
price = price + 1
ElseIf price > 5 Then
price = price – 1
Else
sum = 0
End If
lblAnswer.caption = sum
Price Num Score Sum
2.50 10 142 0
0 0
![Page 11: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/11.jpg)
Question #10
If num = 0 Then
lblAnswer.caption = “Zero”
End If
If score > 2 * num Then
txtNumber.text = 2 * num
Else
txtNumber.text = num
End If
![Page 12: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/12.jpg)
Expressions – If Statements
Written Assignment Solutions
![Page 13: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/13.jpg)
Question #1
a) 21 mod 5 = 1b) 32 \ 2 / 10 = 32 \ 0 = errorc) 32 / 2 \ 10 = 16 \ 10 = 1d) 100 / 2 \ 2 \ 2 = 50 \ 2 \ 2 = 25 \ 2 = 12e) 3 + 5 – 2 * 4 ^ 2 – 6 / 3
= 3 + 5 – 2 * 16 – 6 / 3= 3 + 5 – 32 – 2= -26
![Page 14: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/14.jpg)
Question #2a
If PRICE >= 50 then
PRICE = PRICE – (PRICE * 0.3)
End If
**could also do Price = Price * 0.7
![Page 15: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/15.jpg)
Question #2b
If MARK < 50 Then
COUNTER = COUNTER + 1
End If
![Page 16: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/16.jpg)
Question #2c
If WIN = true Then
SCORE = SCORE +1
Else
SCORE = SCORE -1
End If
![Page 17: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/17.jpg)
Question # 2d
If MARK >= 90 then
MARK = MARK – (MARK * 0.1)
End If
**could also do MARK = MARK * 0.9
![Page 18: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/18.jpg)
Question #2e
If PRICE > 20 then
PRICE = PRCIE + 2
ElseIf PRICE > 10 then
PRICE = PRICE + 1
End If
**be careful of the order of your statements!
![Page 19: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/19.jpg)
Question # 2f
If SCORE = 10 Then
lblMessage.Caption = “Winner!”
ElseIf SCORE < 0 Then
lblMessage.Caption = “Loser!”
End If
![Page 20: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/20.jpg)
Question # 2g
If DONATION > 2000 thenCATEGORY = “Patron”
ElseIf DONATION > 1000 thenCATEGORY = “Helper”
ElseIf DONATION >= 100 thenCATEGORY = “Friend”
ElseCATEGORY = “MEMBER”
End If
**watch out for the order of your statements!
![Page 21: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/21.jpg)
Question #2h
If NUMBER mod 10 = 3 then
NUMBER = NUMBER – 5
End If
**when dividing any number by 10 (doesn’t matter the number of digits) you will get the last digit as the remainder!!
![Page 22: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/22.jpg)
Question #3
If fever > 98.7 Then
health = “ill”
ElseIf fever > 102.0 then
health = “very ill”
Else
health = “normal”
End If
lblHealth.Caption = health
b) Normal
c) ill
d) ill
![Page 23: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/23.jpg)
Question #3 (continued)
e) Any temperature over 98.7 degrees will give you ill as a comment. Any temperature below or equal to 98.7 degrees will give you normal as a comment.
You will never get the comment very ill!!
![Page 24: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/24.jpg)
Question #3 (continued)
If fever > 102.0 thenhealth = “very ill”
ElseIf fever > 98.7 thenhealth = “ill”
Elsehealth = “normal”
End IflblHealth.Caption = health
![Page 25: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/25.jpg)
Question #4
a) Any number that is greater than 1
(2, 3, 4, ….)
a) Any number 14 or less (14, 13, 12, …)
b) This is true for absolutely any number
c) Any even number
d) Any number that has a tens digit of 0, or any single digit number
![Page 26: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/26.jpg)
Question #5 1st method If / ElseIf
Commission = Price * 0.10
If Price > 30000 then
Bonus = (Price – 20000) * 0.10 + 1000
ElseIf Price > 20000 then
Bonus = (Price – 20000) * 0.10
End If
Commission = Commission + Bonus
![Page 27: If Statement Tracing](https://reader035.vdocuments.site/reader035/viewer/2022070404/56813a47550346895da23a2d/html5/thumbnails/27.jpg)
Question #5 2nd method nested if
Commission = Price * 0.10If Price > 20000 then
Bonus = (Price – 20000) * 0.10If Price > 30000 then
Bonus = Bonus + 1000End If
End IfCommission = Commission + Bonus