C++ Nested if
Contoh Program C++ Nested if
source code :
#include <iostream>
using namespace std;
int main()
{
// local variable declaration:
int a = 100, b = 200, c=300;
// check the boolean condition
if( a == 100 ) // melakukan pengecekan kondisi
// apakah nilai a == 100 , jika true / benar
// maka menjalankan if di dalam a=100
{
// if condition is true then check the following
if( b == 200 ) //
{
if(c==300)
{
cout << "Value of a is 100\nand b is 200\nand c is 300"
<< endl;
}
// if condition is true then print the following
//
}
}else
// jika a /= bukan 100 maka akan menjalankan
// yg bukan dalam hierarki a==100.
cout << "Exact value of a is : " << a << endl;
cout << "Exact value of b is : " << b << endl;
return 0;
}
using namespace std;
int main()
{
// local variable declaration:
int a = 100, b = 200, c=300;
// check the boolean condition
if( a == 100 ) // melakukan pengecekan kondisi
// apakah nilai a == 100 , jika true / benar
// maka menjalankan if di dalam a=100
{
// if condition is true then check the following
if( b == 200 ) //
{
if(c==300)
{
cout << "Value of a is 100\nand b is 200\nand c is 300"
<< endl;
}
// if condition is true then print the following
//
}
}else
// jika a /= bukan 100 maka akan menjalankan
// yg bukan dalam hierarki a==100.
cout << "Exact value of a is : " << a << endl;
cout << "Exact value of b is : " << b << endl;
return 0;
}
0 komentar