if (5 == 4) {
//code you want to run if the condition is true
} else {
// code you want to run if the condition is false
}
if (condition)
{
// block of code
}
else if (condition)
{
// block of code
}
else {
// block of code
}
//INCLUDING BUILT-IN LIBRARIES...
#include <iostream>
#include <stdlib.h>
//PRE-DEFINE CONSTANT VALUES...
#define MAXNUM -12 //defining an integer
#define PI 3.1415 //defining a float
#define END "
Program has ended!!
" //defining a string
//PRE-DEFINING CONSTANT OPERATIONS...
#define ADD(a, b, c) (a + b + c) //Operation that will add its 3 parameters
using namespace std;
int main(){
//using other definitions to check if the current device is Windows or UNIX
#ifdef _WIN32
cout<<"Windows Operating System Detected"<<endl;
#elif __unix__
cout<<"UNIX Operating System Detected"<<endl;
#else
cout<<"Operating System could NOT be identified!"<<endl;
#endif
cout<<endl<<"Using pre-defined values and operations: "<<endl;
cout<<" • MAXNUM: "<<MAXNUM<<endl; //using pre-defined integer
cout<<" • PI: "<<PI<<endl; //using pre-defined float
cout<<" • ADD(): "<<ADD(2,5,99.5)<<endl; //using pre-defined function
cout<<END; //using pre-defined string
return 0;
}
if (condition) {
// block of code to be executed if the condition is true
}
int time = 22;
if (time < 10) {
cout << "Good morning.";
} else if (time < 20) {
cout << "Good day.";
} else {
cout << "Good evening.";
}
// Outputs "Good evening."
bool state = (value > 0) ? true : false;
if (condition) {
// body of if statement
}
if(condition)
{
// Statements to execute if
// condition is true
}
if (condition)
{
// Executes this block if
// condition is true
}
else
{
// Executes this block if
// condition is false
}
int x = 20;
int y = 18;
if (x > y) {
cout << "x is greater than y";
}
if(boolean_expression 1) {
// Executes when the boolean expression 1 is true
} else if( boolean_expression 2) {
// Executes when the boolean expression 2 is true
} else if( boolean_expression 3) {
// Executes when the boolean expression 3 is true
} else {
// executes when the none of the above condition is true.
}
int time = 20;
string result = (time < 18) ? "Good day." : "Good evening.";
cout << result;