Monday, June 11, 2018

Contoh program hari if-else bahasa C++

#include <iostream>
using namespace std;

main()
{
ulangi:
int kode;
cout << "masukan kode program (1-7):";
cin >> kode;
if (kode == 1 )
{
cout << "senin";
}
else if(kode == 2)
{
cout << "selasa";
}
else if(kode == 3)
{
cout << "rabu";
}
else if(kode == 4)
{
cout << "kamis";
}
else if(kode == 5)
{
cout << "jum'at";
}
else if(kode == 6)
{
cout << "sabtu";
}
else if(kode == 7)
{
cout << "minggu";
}
else
cout << "kode yang anda masukan tidak ada didalam daftar";
return 0;


}

Labels: , , ,

Membuat program for FIBONACCI bahasa C++

#include <iostream>
using namespace std;
main()
{
 int n,a,b,f,c;
 cout<<"Masukan banyaknya bilangan:";
 cin>>n;
 a=-1;
 b=1;
 cout<<"fibonacci : ";

 for(c=1;c<=n-1;c++){
  f=a+b;
  a=b;
  b=f;
  cout<<" "<<f;
 }
 system ("pause");
}

Labels: , , ,

Contoh program switch bahasa c++

pemograman switch digunakan untuk suatu kondisi untuk memilih sesuatu yang sudah ditetapkan.

#include <iostream>
#include <stdlib.h>
#include <conio.h>


using namespace std;

main()
{
cout << "BONUS YANG AKAN DI DAPATKAN BELI MEMBELI BARANG SENILAI" <<endl;
ulangi:
int jumlah;
cout << "Daftar kode pembelian : " << endl;
cout << "1. 100000 <= pembelian <200000 , bonus  5% " << endl;
cout << "2. 100000 <= pembelian <200000 , bonus tiket ke yogya " << endl;
cout << "3. 100000 <= pembelian <200000 , bonus tiket ke bali" << endl;
cout << "4. 400000 <= pembelian <500000 , bonus Jam Tangan Rolex  " << endl;
cout << "5. pembelian >=500000 , bonus Swiss " << endl;
cout << endl;
cout << "kode(1-5)= ";
cin >> jumlah;
switch(jumlah)
{

case 1:
cout << "bonus 5%" << endl;
break;
case 2:
cout << "bonus tiket ke yogya"<< endl;
break;
case 3:
cout << "bonus tiket ke bali"<< endl;
break;
case 4:
cout << "bonus Jam Tangan Rolex"<< endl;
break;
case 5:
cout << "bonus swiss"<< endl;
break;
}
cout << endl;
goto ulangi;
getch();
}

Labels: , , ,

contoh program while do bahasa c++

contoh program while do

#include <iostream>
#include <conio.h>
#include <stdio.h>

using namespace std;

main()
{
int counter = 0;
do

{
if(counter%2==1)cout << endl << "c++"
<< counter << endl;
counter++;

}
while (counter<15);
getch();
}

Labels: , , ,

contoh program while Bahasa C++

#include <iostream>
#include <conio.h>
#include <stdio.h>

using namespace std;

main()
{
int x =1;
while (x<9)
{

cout << " 1 " << endl << endl;
x++;
}
getch ();
}

Labels: , , ,