Professional Documents
Culture Documents
A==B
In bool means that is 3==3 will be true. True or false is numbers not match. With 3!=3 the statement
will be false.
Control structures
And only some parts are executed in parts if conditions are met
If the numbers is positive or negative to send a message to the user if only positive send only this
message or if its negative only post negative message and skip all others.
Relational Operators
8>15 is ture
6!=6 is false
Comparing characters
It compares letter by letter the closer it is to the beginning the less value it as thus a is the smallest value
in the alphabet and z is the highest.
“hello” > “Hello” would be true. Captial letters have less value than lower case
! not
&& and
|| is or.
Example
!(‘A’>’B’) would be true. It is negation. In reality it would be false because b is bigger than a. but with
the negation change it to true.
Example 2.
(24>=35) && (‘A’<’B’) has a value of false because both have to be true. It won’t test the second part.
Complier wont care to read the second message.
(14>=5) | | (‘A’>’B’) would have a value of true. Only one has to be true in the | | the complier would
read it all unlike and operators.
Order of precedence
Relational and logical operatros are evaluated from left to right like reading
In c++
The or operations
End is equal.
In this equation, multiply first, then do modular, to do subtraction, to execute when done.
Like if a=1 ,
!3=0 because its false so do that first, the multiplication the addition, then to the less than equal to, false
is always 0, so false and false in the &&, 0 is false so it is given a false value
So now
0 || 11
EXAMPLE 1
Double hours
Ex.
If (score >=60)
Grade = ‘P’
{grade =”pass”
Cout << “ … }
If (expression)
Statement 1
Else
Statement 2
If (hours >40.0)
Wages =40*rate +
1.5*rate*(hours -40);
Else
Wages= hours*rate;
Short c e: evaluation of a logical expression stops as soon as the value of the expression is know
(age >=21) || (x ==5) this statement is true. If this is true then they whole things will go to if.if it is all
false then it will go to the else statement.
Syntax for using conditional operator: it can take the place of If else statements.
Switch(integral) expression is evaluated first, value of the expression determines which corresponding
action is taken, expression is sometimes called a selector
Switch ( ) can have any letter value or true values as numbers instead of Boolean statements unlike
the true false statements from the if else statements
{case value 1: __
__
__
Case value 2 ____
___
Default:
Statements
If there is not break in the case values it will keep going when it reaches a break statement is received to
get out of the switch.
Example 1
Switch (grade)
{
Case ‘a’:
Cout << “ the grade point is 4.0.”;
Break;
Case ‘b’:
Cout << “the grade point is 3.0.”;
Default:
Cout << “the grade Is invalid.”;