Mithat Konar
if student’s grade is greater than 60 print "Passed"
If the condition is true the print statement is executed and program goes on to next statement. If the condition is false the print statement is ignored and the program goes onto the next statement.
true
false
if
if (<expression>) <statement>;
if (grade > 60) cout << "Passed" << endl;
bool
>
<
>=
<=
==
!=
=
if student’s grade is greater than or equal to 60 print “Passed” else print "Failed"
If the condition is true the “Passed” print statement is executed and the program goes on to next statement. If the condition is false the “Failed” print statement is executed and the program goes onto the next statement.
if/else
if (<expression>) <statement>; else <statement>;
if (grade >= 60) cout << "Passed" << endl; else cout << "Failed" << endl;
if student’s grade is greater than or equal to 90 print "A" else if student’s grade is greater than or equal to 80 print "B" else if student’s grade is greater than or equal to 70 print "C" else if student’s grade is greater than or equal to 60 print "D" else print "F"
if (grade >= 90) cout << "A" << endl; else if (grade >= 80) cout << "B" << endl; else if (grade >= 70) cout << "C" << endl; else if (grade >= 60) cout << "D" << endl; else cout << "F" << endl;
cout << "This is a simple statement." << endl;
{ x = 3 * y; cout << "The magic number is: " << x << endl; }
if (grade >= 60) cout << "Passed." << endl; else { cout << "Failed." << endl; cout << "You must take this course again." << endl; }
cout << "You must take this course again." << endl;
would be executed no matter what.
if (grade >= 60) cout << "Passed." << endl; else { char yourGrade; yourGrade = 'F'; cout << "You received a grade of " << yourGrade << endl; cout << "You must take this course again." << endl; }
&&
||
!
false && false
false && true
true && false
true && true
false || false
false || true
true || false
true || true
!false
!true
assume: int x = 12, y = 5, z = -4;
int x = 12, y = 5, z = -4;
(x > y) && (y > z)
(x > y) && (z > y)
(x <= z) || (y == z)
(x <= z) || (y != z)
!(x >= z)