Showing posts with label cplusplus. Show all posts
Showing posts with label cplusplus. Show all posts

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 :


Contoh Sederhana Program C++:Program Umur Dan bilangan genap dan ganjil

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

Dibawah ini saya akan menulis Beberapa contoh program sederhana yang menggunakan bahasa C++, Saya juga menambahkan gambar saat dicompile beserta Hasilnya.

Contoh 1 : Program Umur 
//Program Umur
#include <iostream.h>
#include <conio.h>
void main ()
{int usia;
clrscr();
cou<<" Berapa Usia Anda ?? ";
cin>>usia;
if (usia<17)
    cout << " Anda Belum Dewasa " <<endl;
else
    cout << " Anda Dewasa " <<endl;
}

Compile :


Hasilnya :



Contoh 2: Program Bilangan Ganjil Genap
//program bilangan ganjil genap
#include <iostream.h>
#include <conio.h>
void main()
{int bilangan;
clrscr();
    cout << " Masukan Angka = ";
cin>>bilangan;
if (bilangan %2==0)
    cout << " Bilangan Genap "<<endl;
else
    cout << " Bilangan Ganjil "<<endl;
}


Compile :


Hasil :


Translate