Programming CPP Lesson2 ConditionalStatement Autosaved
Programming CPP Lesson2 ConditionalStatement Autosaved
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 {
}
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”