Contoh Program C++: jabatan dan pilihan

Preh-Solusi /Sabtu, 2 April 2016 17:40

Contoh 1 : Program Jabatan
//Program Jabatan
#include <iostream.h>
#include <conio.h>
void main()
{int a;
clrscr();
cout<<" Masukan Code Jabatan = ";
cin>>a;
if(a==1)
{    cout << "Golongan Anda I"<<endl;
    cout << "Gaji Anda Rp.1000"<<endl;
    cout << "Anda Orang Miskin"<<endl;
    }
else
{    cout << "Golongan Anda II"<<endl;
    cout << "Gaji Anda Rp.2000"<<endl;
    cout << "Anda Orang Kaya"<<endl; 
    }
}

Compile :


Hasil :



Contoh 2 : Program Pilihan
//Program Pilihan Item
#include <iostream.h>
#include <conio.h>
void main()
{int pilihan;
clrscr();
cout<< " Silahkan Pilih 1 Item \n\n";
cout<< " 1.pilihan 1\n ";
cout<< " 2.pilihan 2\n ";
cout<< " 3.pilihan 3\n ";
cout<< " 4.pilihan 4\n ";
cout<< " Masukan Pilihan [1..4] = ";
cin>>pilihan;
switch(pilihan)
{    case 1 :
        cout<<" anda memilih nomor 1 \n" <<endl;
        break;
    case 2 :
        cout<<" anda memilih nomor 2 \n" <<endl;
        break;
    case 3 :
        cout<<" anda memilih nomor 3 \n" <<endl;
        break;
    case 4 :
        cout<<" anda memilih nomor 4 \n" <<endl;
        break;
    default:
        cout<<" anda salah pilih \n" <<endl;
        break;
}    }


Compile :


Hasil :


Share this

Related Posts

Previous
Next Post »

Translate