0% found this document useful (0 votes)
220 views

Lecture 04 C++ Conditional Statement (ES 1EE)

The document discusses if statements in C++. It provides examples of basic if statements, if-else statements, and uses if statements to solve problems by checking conditions and executing code blocks based on the results. Examples include checking if a product is greater than 250 and computing a student's average grade to determine if they passed or need better luck next time. The final problem checks if a number is less than 50 before dividing it.

Uploaded by

John Clemente
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
220 views

Lecture 04 C++ Conditional Statement (ES 1EE)

The document discusses if statements in C++. It provides examples of basic if statements, if-else statements, and uses if statements to solve problems by checking conditions and executing code blocks based on the results. Examples include checking if a product is greater than 250 and computing a student's average grade to determine if they passed or need better luck next time. The final problem checks if a number is less than 50 before dividing it.

Uploaded by

John Clemente
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

10/9/2020

if statement
• If statements in C++ is used to control the
program flow based on some condition, it's
used to execute some statement code block
if the expression is evaluated to true.
Otherwise, it will get skipped.
C++ Conditional • Syntax:
Statement • if(test_expression)
MICHAEL B. FRANCISCO, LPT, MIT • statement;
PROFESSOR

if statement if statement
• Comprasion Operators • Example 1:
• Less than (<)
• Greater than (>)
• Less than or equal to (<=)
• Greater than or equal to (>=)
• Equals (==)
• Not equals (!=)
10/9/2020

if statement if statement
• Example 2: • Example 3:

if-else statement if-else statement


• Syntax: • Example 4:
if (condition)
statement1;
else
statement2;
10/9/2020

if-else statement Problem 1


• Example 5: • Make a program that input 2 numbers and
calculate their product. If the product is
greater than or equal 250, display, “Hooray!”.

Problem 1 Problem 2
• Create a program that compute the
average grade of the student in C++ Subject.
Input the Name, Prelim, Midterm and Final
grade . If the average grade is greater than
or equal to 75, display “Passed!” and if not
display “Better Luck Next Time!”
10/9/2020

Problem 2 Problem 3
•Enter any integer number. If the
inputted integer number is less
than 50, display “The number is
too small.” otherwise, divide the
integer number by 5 times 2 and
display it.

Problem 3

You might also like