C++ Demo if elseif

Contoh Program C++ Demo if elseif


source code :

#include <iostream>

using namespace std;

int main()
{
    /* buatkan program untuk menentukan
    tingkatan berdasarkan usia
    jika usia <4 -> balita
    jika usia >4 - 7 -> Taman Kanak-kanak
    jika usia 7-13 -> SD
    jika usia 13-16 -> Anda SMP
    jika usia 16-18 -> anda SMA
    jika usia 18-23 -> Anda Sudah Sarjana
    jika usia > 23 -> Anda sudah tua
    */
    // local variable declaration:
   int a = 20;
   // check the boolean condition
   if( a == 10 )
   {  // if condition is true then print the following
       cout << "Value of a is 10" << endl;
   }
   else if( a == 20 )
   {   // if else if condition is true
       cout << "Value of a is 20" << endl;
   }
   else if( a == 30 )
   {  // if else if condition is true
       cout << "Value of a is 30" << endl;
   }
   else
   {   // if none of the conditions is true
       cout << "Value of a is not matching" << endl;
   }
   cout << "Exact value of a is : " << a << endl;
    return 0;
}

Share:

0 komentar