CMPSC 201 Chapter Notes - Chapter 4: Boolean Expression

43 views3 pages
School
Course
Relational operators: Determines whether a relationship exists between two values
>= : Greater than or equal to
<= : Less than or equal to
== : Equal to
!= : Not equal to
Relational operators are binary
Relational expressions are Boolean expression (true or false only)
== Determines whether a variable is equal to another value
= Assigns operator’s left value to the right value
Relational expressions have a higher precedence than assignment operators
The if statement can cause other programs to be executed only under certain conditions
if (condition)
cout << “statement” ;
To prevent round off errors, it’s better to stick with less than or greater than sign
For if statements, anything other than 0 is true
Always use braces. Ex-
if (condition)
{statement
statement
statment}
if the if statement is not true, the the program follows the else statement
Nested if. If two statements exist then,
if ( condition 1)
{ if (condition 2)
{ cout <<statement
}
else //for statement 2
{
}
}
else (statement 1)
{
cout <<
}
if/ else if method:
If (statement 1 is true)
{ steps
}
else if (statement 2 is true) - it is called the trailing else
{steps
}
else (if none is true)
The disadvantages of if/ else if statements:
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Relational operators: determines whether a relationship exists between two values. Relational expressions are boolean expression (true or false only) == determines whether a variable is equal to another value. = assigns operator"s left value to the right value. Relational expressions have a higher precedence than assignment operators. The if statement can cause other programs to be executed only under certain conditions if (condition) cout << statement ; To prevent round off errors, it"s better to stick with less than or greater than sign. For if statements, anything other than 0 is true. {statement statement statment} if the if statement is not true, the the program follows the else statement. If two statements exist then, if ( condition 1) { cout <

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents