0% found this document useful (0 votes)
21 views9 pages

Programming CPP Lesson2 ConditionalStatement Autosaved

The document discusses different types of conditional statements in C++ including if, if-else, ladderized if, and nested if statements. It provides the syntax and examples of using each statement type to check conditions and execute code blocks accordingly. Key conditional operators like >, <, ==, etc. are also defined. The document concludes with proposing activities to design programs using conditional statements to determine the largest number, current day of the week, and weather based on temperature.

Uploaded by

echalasjeanu7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views9 pages

Programming CPP Lesson2 ConditionalStatement Autosaved

The document discusses different types of conditional statements in C++ including if, if-else, ladderized if, and nested if statements. It provides the syntax and examples of using each statement type to check conditions and execute code blocks accordingly. Key conditional operators like >, <, ==, etc. are also defined. The document concludes with proposing activities to design programs using conditional statements to determine the largest number, current day of the week, and weather based on temperature.

Uploaded by

echalasjeanu7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

CONDITIONAL

STATEMENT

MR. ALDRINE SORIANO


COMPARISON LOGICAL
OPERATOR OPERATOR
• > - Greater Than • && - Both condition needs
• < - Less Than to be true

• >= - Greater than or equal to • || - either one of condition


needs to be true
• <= - Less than or equal to
• != - not equal to
• == - equal to
DIFFERENT TYPES OF CONDITIONAL
STATEMENT
IF STATEMENT? • Contains only one condition.

IF-ELSE STATEMENT? • Contains one condition and an else.

LADERIZE IF • Multiple condition and an else.


STATEMENT?
NESTED IF • Condition within a condition.
STATEMENT?
SIMPLE IF STATEMENT

SYNTAX: APPLICATION:

IF (condition) { IF (10>5){
//STATEMENT cout<< “True”;
} }
IF-ELSE STATEMENT
SYNTAX: APPLICATION:
x = 20;
y= 10;
IF (condition) {
//STATEMENT IF (x < y) {
} cout << “False”;
}
ELSE {
ELSE {
//STATEMENT
cout << “True”;
} }
LADDERIZE IF STATEMENT
SYNTAX: APPLICATION:
Int n = 2;
IF (condition) { IF (n == 1) {
//STATEMENT cout << “False”;
} }
ELSEIF (condition) { ELSEIF (n == 2){
//STATEMENT cout << “True”;
} }
ELSEIF (condition) { ELSEIF (n == 3){
//STATEMENT cout << “False”;
} }
ELSE { ELSE {
//STATEMENT cout << “False”;
} }
NESTED IF STATEMENT
SYNTAX: APPLICATION:
Int n1, n2, n3;
n1 = 5;
IF (condition) {
n2 = 10;
IF (condition) {
n3 = 3;
//STATEMENT IF (n1 > n2) {
} IF (n1 > n3) {

ELSE { cout << n1;


}
//STATEMENT
ELSE {
} cout << n3;
} }

ELSE {
}
IF (condition) {
ELSE {
//STATEMENT
IF (n2 > n3) {
} cout << n2;
ELSE { }

//STATEMENT ELSE {
cout << n3;
}
}
} }
ACTIVITY
#1 WHAT IS THE LARGEST
#2 WHAT DAY IS TODAY? #3 WEATHER CHECK
NUMBER?
 Create & Design a program  Create & Design a program that can  Create a program that can
that can determine the determine the day from Monday to determine the weather based
largest number. Sunday (1-7) based on the user on the temperature given by
 The form title should be the input. the user.
name of this activity.  If the user give a value that outside  Freezing Point is below 0°,
 Of course as always, use label of the range given, display this From 0° to 10° is Very Cold,
in displaying the result. message “Invalid Input! Please 11° to 20° is Cold, 21° to 30 is
Enter Number from 1-7.” Normal, 31° to 40° is Warm,
 The form title should be the name 41° to 50° is Hot, and 50°
of this activity. above is Very Hot.
 Display the result by using a label.  However, if the temperature
reach or surpassed 100° it
should be Boiling Point
 The result will be displayed
on a label.
“IF YOU’RE NOT WILLING TO
LEARN, NO ONE CAN HELP YOU,
IF YOU’RE DETERMINED TO LEARN,
NO ONE CAN STOP YOU”

You might also like