Professional Documents
Culture Documents
STRUCTURES
SEQUENTIAL
DECISION/SELECTION
SWITCH
LOGICAL CONTROL
STRUCTURES
SEQUENTIAL
DECISION/SELECTION
SWITCH
C++ if statement
An if statement executes
when the Boolean
expression is TRUE.
Syntax:
if(boolean_expression)
{
// statement(s) will execute if the boolean
expression is true
}
If the boolean expression
evaluates to true, then
the if block of code will
be executed
if( a > 20 )
{
cout << "a is greater than 20" << endl;
}
C++ if...else statement
An if statement can be
followed by an optional
else statement, which
executes when the Boolean
expression is false.
Syntax:
if(boolean_expression)
{
// statement(s) will execute if the boolean
expression is true
}
else
{
// statement(s) will execute if the boolean
expression is false
}
If the boolean expression
evaluates to true, then
the if block of code will
be executed, otherwise
else block of code will be
executed.
if( a < 20 )
{
cout << "a is less than 20;" << endl;
}
else
{
cout << "a is not less than 20;" << endl;
}
if (april == 99)
cout<<“ F is for fire that burns down the whole
town”;
else
cout<<“ F is for friends who do stuff together!”;
Exercise
if ((c+d)>= m))
cout<<“ U is for uranium, bombs”;
else
cout<<“ U is for you and me”;
Exercise
if ((score<= 80)&&(score==85))
cout<<“ N is for no survivors when you're-”;
else
cout<<“ N is for anywhere and anytime at
all”;
Exercise
if (grade > 90 )
cout<< “ Excellent ”;
else if (grade > 85)
cout<< “ Very Good ”;
else if (grade > 80)
cout<< “ Good ”;
else
cout<< “ Poor ”;
Exercise
d = d + c / a – b;
if (d == – 94)
cout<<"Peace";
else
cout<<”Love";
Exercise
z = x * y % z;
if (y >= 10)
cout<<"Good”;
else
cout<<"Bad";
Activity1.cpp
Write a Java program for applying
a driver’s license. User will enter
their age and it should give a
feedback that the user can’t get a
driver’s license under the age of
18.
Make a simple switch program
that will determine if you are 1st
year, 2nd year, 3rd year, 4th year
or not a student.