conditional statement ss1

28
Conditio nal Statemen t

Upload: jordan-delacruz

Post on 23-Dec-2014

2.220 views

Category:

Technology


7 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Conditional statement ss1

Conditional Statement

Page 2: Conditional statement ss1

Conditional Statements

•Are statements that check an expression then may or may not execute a statement or group of statement depending on the result of the condition.

Page 3: Conditional statement ss1

TYPES

1.IF-THEN STATEMENT

2.IF-THEN-ELSE STATEMENT

3.LADDERIZED IF-THEN-ELSE STATEMENT

Page 4: Conditional statement ss1

IF-THEN STATEMENT

• It specifies that a certain statement will be executed only if the expression is true

Page 5: Conditional statement ss1

SYNTAX

• IF condition THEN expression

Page 6: Conditional statement ss1

Example

IF the telephone is ringing THENanswer the telephone

Page 7: Conditional statement ss1

RELATIONAL OPERATIONS

1.=

2.>

3.<

4.>=

5.<=

Page 8: Conditional statement ss1

SAMPLE PROBLEMS

Page 9: Conditional statement ss1

•Write a program that will output “Congratulations!” if the student’s grade is greater than or equal 75.

Page 10: Conditional statement ss1

Rem

Clear

Input G

IF G>=75 THEN Print “Congratulations!”

End

Page 11: Conditional statement ss1

•Write a program that will ask for a price. If the price is greater than 1000, compute a 10% discount from the original price. Display the computed discount.

Page 12: Conditional statement ss1

Clear

Input P

If P>1000 THEN d=P*.1

Print d

End

Page 13: Conditional statement ss1

IF-THEN-ELSE Statement

•It allows the computer to choose one of the given two alternatives.

Page 14: Conditional statement ss1

SYNTAX

•IF condition THEN expression1 ELSE expression2

Page 15: Conditional statement ss1

SAMPLE PROBLEMS

Page 16: Conditional statement ss1

•Write a program to print for the sum of two numbers if the first no. is greater than the second no., otherwise print their difference

Page 17: Conditional statement ss1

REM

Clear

Input x,y

If x>y THEN S=x+y : Print S

ELSE

D=x-y : Print D

End

Page 18: Conditional statement ss1

•Write a program that determines if the input age is qualified to vote or not. If qualified, displays “Qualified to Vote!” if not displays “Too Young!” We know that a qualifying age is 18 yrs. old and above.

Page 19: Conditional statement ss1

REM

Clear

Input A

If A>=18 THEN Print “Qualified to vote!”

ELSE Print “Too Young!”

End

Page 20: Conditional statement ss1

NESTED IF or LADDERIZED IF-THEN-ELSE Statement

•is used if there are three or more possible conditions and outcomes to be executed.

Page 21: Conditional statement ss1

SYNTAX

IF condition1 THEN

Expression1

ELSE IF condition2 THEN

Expression N

ELSE

Expression

Page 22: Conditional statement ss1

SAMPLE PROBLEMS

Page 23: Conditional statement ss1

•Write a program that displays an equivalent color once an input letter matches its first character for example b is for blue, r for red and so on. Here is the given criteria.

Letters Colors“B” or “b” Blue“R” or “r” Red“G” or “g” Green“Y” or “y” Yellow

Other letters Unknown Color

Page 24: Conditional statement ss1

REM

Clear

Input x

IF x=b THEN Print “Blue”

ELSE IF x=r THEN Print “Red”

ELSE IF x=g THEN Print “Green”

ELSE IF x=y THEN Print “Yellow”

ELSE Print “Unknown Color!”

Page 25: Conditional statement ss1

ASSIGNMENT

Page 26: Conditional statement ss1

1. Write a program to display the high school level of a student, based on its year entry number for example the year-entry 1 means the student is a freshmen, 2 for sophomore, and so on. Here are the given criteria:Year-Entry Number High School Level

1 Freshmen

2 Sophomore

3 Junior

4 Senior

Other Entry No. Out-of-School

Page 27: Conditional statement ss1

Write a program that examine the value of a variable called temp. then display the following messages depending on the value assigned to the temp.

Temperature Message

Less than 0 ICE

Between 0 and 100 Water

Exceeds 100 STEAM

Page 28: Conditional statement ss1

T. O. L.