!a && b < c || d == 0
bool isEqual(int x, int y)
{
return x == y;
}
int main()
{
bool b = true;
b = isEqual(3, 4);
b = false;
return 0;
}
bool cond = divisor > 0 && numerator / divisor > 0.1;
bool notADigit = c < '0' || c > '9';
bool isAChild = age < 18; bool isAdult = !isAChild;
int main()
{
int a = 1;
int b = 2;
if ( a < b )
cout << "a < b\n";
else if ( a > b )
cout << "a > b\n";
else
cout << "a == b\n";
if ( a > 0 )
cout << "a is positive\n"0;
}
int maxOfThree( int a, int b, int c )
{
if ( a < b )
if ( b < c )
return c;
else
return b;
else if ( a < c )
return c;
else
return a;
}
if ( e ); // extra semicoln means empty statements cout << "Hello"; // prints "Hello" even if e is false
if ( e ) ; // nothing else cout << "Hello";
int a = 0; if ( a = 0 ) cout << "Hello"; // never happens! Why?
if ( a < b ) return true; else return false;
return a < b;
int main()
{
int i = getIntegerFromUser();
cout << "Some stuff here\n";
switch ( i )
{
case 1:
case 3:
case 5:
case 7:
case 9:
cout << i << " is odd\n";
break;
case 0:
case 2:
case 4:
case 6:
case 8:
cout << i << " is even\n";
break;
default:
cout << i << " isn't in range 0 to 9\n";
break;
}
cout << "Some more stuff here\n";
}
bool isDigit( char c )
{
switch ( c )
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return true;
default:
return false;
}
}
int main()
{
int score = getScoreFromUser();
char grade = computeStudentsGrade( score );
switch ( grade )
{
case 'A':
cout << "Excellent!\n";
case 'B':
cout << "Good.\n";
case 'C':
cout << "Fair - just passed.\n";
case 'D':
cout << "Poor - See you next quarter.\n";
case 'F':
cout << "Failed - off to OCC.\n";
defaut:
cout "Invalid Grade " << grade << endl;
}
}
bool isDigit(char c)
{
switch ( c )
{
case '0'-'9': // will subtract '9' from '0'
return true;
default:
return false;
}
}
bool isDigit(char c)
{
switch ( c )
{
case '0':
case '1':
case '2':
/// do something here
default:
return false;
}
}