Академический Документы
Профессиональный Документы
Культура Документы
CONDITIONAL
STATEMENTS
CSCC 102 KATHRINA T. DACANAY
Course Outline
1. if Statement
2. if-else Statement
3. if-else if Statement
4. switch Statement
1 if Statement
if Statement Syntax
if (condition)
statement_TRUE;
if Statement Examples
if (age >= 18)
printf(“Allowed to Vote!”);
if (condition)
statement_TRUE;
else
statement_FALSE;
if-else Statement Examples
if (age >= 18)
printf(“Allowed to Vote!”);
else
printf(“Not allowed to Vote!”);
if (condition1)
statement_TRUE1;
else if(condition2)
statement_TRUE2;
:
else
statement_FALSE;
if-else if Statement Example
if ((age >= 18) && (age <= 100))
printf(“Allowed to Vote!”);
else if (age >= 101)
printf(“6 feet under!”);
else if ((age >= 12) && (age <= 17))
printf(“Too young to vote!”);
else if ((age >= 7) && (age <= 11))
printf(“Kid!”);
else if ((age >= 0) && (age <= 6))
printf(“Toddler!”);
else
printf(“Age does not exist!”);
4 switch Statement
switch Statement Syntax
switch(variable) {
case value1:statement_val1;
break;
case value2:statement_val2;
break;
:
default: statement_FALSE;
}
switch Statement Example
switch (num) {
case 1: printf(“ONE”);
break;
case 2: printf(“TWO”);
break;
case 3: printf(“THREE”);
break;
default: printf(“Bye!”);
}
Review Exercises
Directions: Give the output of the program below if the
respective values are entered for variables num1 and
num2. #include<stdio.h>
int num1, num2;
1.num1 = 90; num2 = 80;
SUMMARY
Subject Grade Numerical Rating Remarks
Introduction to Computing 88 2.00 Passed
Fundamentals of Programming 90 1.75 Passed
Art Appreciation 95 1.25 Passed
Purposive Communication 90 1.75 Passed
Mathematics in the Modern World 70 5.00 Failed
Kontekstwalisadong Komunikasyon sa Filipino 92 1.50 Passed
Fundamentals of Physical Fitness: 94 1.50 Passed
Programming Exercises
3. A simple Body Mass Index (BMI) Calculator app. Create a BMI
calculator application that reads the user’s weight in pounds (ok
kilograms) and height in inches, then calculates and displays the
user’s BMI. The formulas for calculating BMI are: