Professional Documents
Culture Documents
Selection Statements: By: Engr. Neil P. Magloyuan
Selection Statements: By: Engr. Neil P. Magloyuan
Overview
To process a program, the computer begins at the first executable statement and
executes the statements in order until it comes to the end. This module, you will
learn how to tell a computer that it does not have to follow a simple sequential order
of statements; it can also make decisions and are used to alter the sequential flow of
execution. The two most common control structures are selection and repetition but
this module tackles the selection structure which programs executes particular
statements depending on some condition(s).
Selection Statements 1
Activity
#include <iostream>
#include <iomanip>
int main( )
double creditCardBalance;
double payment;
double balance;
if (balance > 0)
cout << "Line 21: The balance is: Php " << balance<< endl;
cout << "Line 22: The penalty to be added to your "<< "next month bill is: Php "<<
penalty << endl;
return 0;
Selection Statements 1
Selection Statements 1
3.2 If Else Then Statement
Learning Outcomes
Introduction
There are many programming situations in which you must choose between two
alternatives. For example, if a part-time employee works overtime, the paycheck is
calculated using the overtime payment formula; otherwise, the paycheck is calculated
using the regular formula. In this way, you choose between two alternatives-that is, to
implement two-way selections and that is using the if…else statement. This lesson
provides you with these learnings.
Activity
#include <iostream>
#include <iomanip>
int main( )
{ int score;
Selection Statements 1
cout << "The grade is F." << endl;
}
Selection Statements 1
4.3 Switch Statement
Learning Outcomes
Introduction
Recall that there are two selection or branch structures in C++. The first selection
structure, which is implemented with if and if…else statements, usually requires the
evaluation of a logical expression. The second selection structure, which does not
require the evaluation of a logical expression, is called a switch structure. This lesson
will teach you how to use this structure
Acti vity
#include <iostream>
int main ()
int num;
switch (num) {
case 0:
case 1:
Selection Statements 1
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
case 7:
break;
default:
return 0;
Selection Statements 1
Selection Statements 1