Laporan Akhir 3 Switch

MASUKAN SYNTAX SEPERTI DIBAWAH INI PADA LEMBAR KERJA TURBO C++ :

#include <iostream.h>
#include <conio.h>
int pil,kambing,kambing2,beli1,beli2,total_beli,pot1,pot2,kawin2;
long total_harga,modal;
void main ()
{
clrscr();
                gotoxy(30,15);cout<<"Masukan Modal Usaha Anda : ";cin>>modal;
                menu:
                clrscr();
                gotoxy(30,2);cout<<"Kambing Jantan yg anda punya : "<<kambing;
                gotoxy(30,3);cout<<"Kambing Betina yg anda punya : "<<kambing2;
                gotoxy(30,4);cout<<"Modal yg Anda punya sekarang : "<<modal;
                gotoxy(21,5);cout<<"=====PT. TERNAK KAMBING=====";
                gotoxy(20,6);cout<<"1. Beli Kambing";
                gotoxy(20,7);cout<<"2. Jalankan Ternak";
                gotoxy(20,8);cout<<"3. Keluar";
                gotoxy(30,9);cout<<"Masukan Pilihan (1/2/3) : ";cin>>pil;
                switch (pil)
                {
                                case 1:
                                                menubeli:
                                                clrscr ();
                                                cout<<"Harga Kambing Jantan @500.000 ";
                                                cout<<"\nHarga Kambing Betina @750.000 ";
                                                cout<<"\nBerapa Beli Kambing jantan : ";cin>>beli1;
                                                cout<<"\nBerapa Beli Kambing betina : ";cin>>beli2;
                                                total_harga = (beli1*500000)+(beli2*750000);
                                                if (modal < total_harga)
                                                {
                                                                cout<<"\nModal Juragan tidak cukup";
                                                                getch ();
                                                                goto menubeli;

                                                }
                                                else
                                                {
                                                                cout<<"\nTotal Harga : "<<total_harga;
                                                                cout<<"\nMantap Gan!!, nanti beli lagi ya";
                                                                kambing = kambing + beli1;
                                                                kambing2= kambing2 + beli2;
                                                                modal = modal - total_harga;
                                                                getch();
                                                                goto menu;
                                                }
                                case 2:
                                                clrscr ();
                                                cout<<"====OPERASI KAMBING ATA 2011/2012====";
                                                cout<<"\n1. Potong kambing";
                                                cout<<"\n2. Kawinin kambingnya";
                                                cout<<"\n3. Ikuti kontes Miss Kambing";
                                                cout<<"\n4. Balik Ke menu Sebelumnya";
                                                cout<<"\nMasukan Pilihan : ";cin>>pil;
                                                switch (pil)
                                                {
                                                                case 1:
                                                                                clrscr();
                                                                                cout<<"\nMasukan Jumlah Jantan yg ingin dipotong : ";cin>>pot1;
                                                                                cout<<"\nMasukan Jumlah betina yg ingin dipotong : ";cin>>pot2;
                                                                                if (kambing < pot1)
                                                                                                cout<<"\nKambing jantan tidak Cukup";
                                                                                else
                                                                                                kambing = kambing - pot1;
                                                                                if (kambing2 < pot2)
                                                                                                cout<<"\nkambing Betina tidak cukup";
                                                                                else
                                                                                                kambing2 = kambing2 - pot2;
                                                                                cout<<"\nTerima kasih telah memotong kambing";
                                                                                getch ();
                                                                                goto menu;
                                                                case 2:
                                                                                clrscr();
                                                                                cout<<"\nMinimal anda harus mempunyai 3 Betina dan 1 Jantan untuk dikawinkan gan.";
                                                                                if (kambing < 1)
                                                                                {
                                                                                gotoxy(1,3);cout<<"\nAnda tidak mempunyai Jantan sama sekali,beli dulu sana!";
                                                                                getch ();
                                                                                goto menubeli;
                                                                                }
                                                                                else
                                                                                cout<<"\nBerapa Ekor betina yg ingin anda kawinkan : ";cin>>kawin2;
                                                                                if (kambing2 < kawin2)
                                                                                                cout<<"\nKambing Betina anda ga ada gan";
                                                                                else
                                                                                                kambing2 = kambing2 - kawin2;
                                                                                if (kambing < 1)
                                                                                                cout<<"\nAnda Gak Punya Kambing Jantan Gan, ga bisa kawin dong";
                                                                                else
                                                                                                kambing = kambing - 1;
                                                                                cout<<"\nTerima kasih telah Mengawinkan Kambing anda";
                                                                                getch();
                                                                                goto menu;
                                                                case 3:
                                                                                clrscr();
                                                                                cout<<"\n===SELAMAT DATANG DI AJANG KONTES MISS KAMBING SEJAGAD===";
                                                                                cout<<"\nuntuk mengikuti kontes ini Agan Minimal harus mempunyai 3 Kambing betina...";
                                                                                if (kambing2 >= 3)
                                                                                {
                                                                                gotoxy(1,4);cout<<"sekarang anda memiliki "<<kambing2;cout<<" Ekor Betina";
                                                                                gotoxy(1,5);cout<<"\nSelamat anda dapat mengikuti kontes ini";
                                                                                getch ();
                                                                                goto menu;
                                                                                }
                                                                                else
                                                                                {
                                                                                gotoxy(1,4);cout<<"\nMaaf anda hanya memiliki "<<kambing2;cout<<" Ekor betina";
                                                                                gotoxy(1,5);cout<<"\nAnda tidak bisa mengikuti kontest ini, Beli Dulu Sana!!!";
                                                                                }
                                                                                getch ();
                                                                                goto menubeli;
                                                                case 4:
                                                                                goto menu;
                                                                default:
                                                                                cout<<"\nPilihan Salah pak";
                                                }
                                case 3:
                                                gotoxy(10,10);cout<<"Terima Kasih telah bermain dgn kambing, Mbeeekk!!";
                                                break;
                                default:
                                                gotoxy(10,11);cout<<"Pilihan Salah Gan!!!";
                                                getch ();
                                                goto menu;
                }
}
getch ();


LALU AKAN KELUAR OUTPUT SEPERTI GAMBAR DIBAWAH INI dengan menekan tombol CTRL + F9 :











LOGIKANYA adalah : Fungsi #include{iostream.h} adalah Pada program diatas digunakan untuk menampulkan dungsi cin dan cout yang berguna untuk input – output program diatas. Fungsi #include{conio.h} adalah digunakan untuk menampilkan getch(tahan) yang akan digunakan untuk merunning coding diatas. Tipe data yang digunakan adalah int (integer = untuk memasukan nilai bulat atau angka tetepi terbatas) dan Long = untuk menampilkan nilai atau bilangan bulat yang lebih panjang dan banyak daripada integer. Gotoxy diatas berati menunjukan (kolom,baris) untuk menampilkan kata-kata yang berada didalam tanda kutip (“....”). Mengapa harus menggunakan “else” ? karena jika modal yang anda punya sudah cukup akan secara otomatis setelah menekan “enter” akan kembali kemenu utama. Fungsi break adalah misalnya case 1 pada akhir statement ada lompatan (go to menu) . kalo break dihapus maka program secara otomatis akan menjalankan  program yang berada dibawahnya (default) . Dan, seperti itulah logika yang saya samaikan dalam percobaan kali ini ..
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

0 Response to "Laporan Akhir 3 Switch"

Posting Komentar