C++ Perulangan dengan Go To

Belajar buat program C++ lagi Gan... Pada postingan yang dulu ane sudah memposting program Perulangan menggunakan "Do While", bisa dilihat di C++ Perulangan. Tapi kali ini ane mau memposting program perulangan menggunakan "Goto". Caranya tidak jauh beda sama program "Do While", sangat simple sekali. Langsung saja Gan ke source Code'a...



==================================================

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

main()

{
   int no,pil;
    float a,b,c,x,y,z;
   float phi=3.14;
   char nama [30];
       user:
         cout<<"Masukkan Nama User : "; cin>>nama; system ("cls");
      milihmenu:
      clrscr();
      cout<<"Welcome Mr. "<<nama<<""<<endl<<endl;
      cout<<" ------------------------ MENU -------------------------"<<endl;
        cout<<" |  [1] Matematika Dasar                               |"<<endl;
        cout<<" |  [2] Bangun Ruang                                   |"<<endl;
      cout<<" |  [3] Keluar                                         |"<<endl;
      cout<<" -------------------------------------------------------"<<endl<<endl;

    cout<<" Silahkan Masukkan Pilihan Menu Anda : ";
    cin>>pil;

   if (pil==1)
       { goto dasar;}
   else if (pil==2)
       { goto ruang;}
   else
       { goto keluar; }

   ruang:
   {
       clrscr();
      cout<<"==============================="<<endl;
      cout<<"          Bangun Ruang         "<<endl;
      cout<<"==============================="<<endl;
      cout<<endl;
      cout<<" =*= PILIHAN PROGRAM =*= "<<endl<<endl;
      cout<<" 1. Luas Segitiga "<<endl;
      cout<<" 2. Luas Persegi Panjang "<<endl;
      cout<<" 3. Luas Lingkaran "<<endl;
      cout<<" 4. Luas Belah Ketupat "<<endl;
      cout<<" 5. Luas Trapesium "<<endl;
      cout<<" 6. Keiling Segitiga "<<endl;
      cout<<" 7. Keiling Persegi "<<endl;
      cout<<" 8. Keiling Lingkaran "<<endl;
      cout<<" 9. Keiling Belah Ketupat "<<endl;
      cout<<"10. Keiling Trapesium "<<endl;
      cout<<endl;

      cout<<"Masukkan Pilihan Program = "; cin>>no;
      cout<<endl;

      if (no==1)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<" =*= Program Luas Segitiga =*="<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Nilai Alas    = "; cin>>x;
      cout<<"Masukkan Nilai Tinggi  = "; cin>>y;
      cout<<endl;
      cout<<"Luas Segitiga          = 1/2 * "<<x<< " * "<<y<<endl;
      z=0.5*x*y;
      cout<<"Luas Segitiga          = "<<z<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if(no==2)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<" =*= Luas Persegi Panjang =*=  "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Nilai Panjang  = "; cin>>a;
      cout<<"Masukkan Nilai Lebar    = "; cin>>b;
      cout<<endl;
      cout<<"Luas Persegi Panjang    = "<<a<<" * "<<b<<endl;
      c=a*b;
      cout<<"Luas Persegi Panjang    = "<<c<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if(no==3)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"    =*= Luas Lingkaran =*=     "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Jari - Jari  = "; cin>>a;
      cout<<endl;
      cout<<"Luas Lingkaran        = 3.14 * "<<a<<" * "<<a<<endl;
      b=phi*a*a;
      cout<<"Luas Lingkaran        = "<<b<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;  cout<<endl;
      }

      if (no==4)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"  =*= Luas Belah Ketupat =*=   "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Nilai Alas        = "; cin>>x;
      cout<<"Masukkan Panjang Diagonal  = "; cin>>y;
      cout<<endl;
      cout<<"Luas Belah Ketupat         = 1/2 * "<<x<<" * "<<y<<endl;
      z=0.5*x*y;
      cout<<"Luas Belah Ketupat         = "<<z<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if (no==5)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"  =*= Luas Trapesium =*=   "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Sisi Pertama = "; cin>>x;
      cout<<"Masukkan Sisi Kedua   = "; cin>>y;
      cout<<"Masukkan Nilai Tiggi  = "; cin>>z;
      cout<<endl;
      cout<<"Luas Trapesium        = 1/2 * ( "<<x<< " + "<<y<<" ) * "<<z<<endl;
      a=0.5*(x+y)*z;
      cout<<"Luas Trapesium        = "<<a<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if (no==6)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"  =*= Keliling Segitiga =*=    "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Sisi Pertama = "; cin>>x;
      cout<<"Masukkan Sisi Kedua   = "; cin>>y;
      cout<<"Masukkan Sisi Ketiga  = "; cin>>z;
      cout<<endl;
      cout<<"Keliling Segitiga     = "<<x<<" + "<<y<<" + "<<z<<endl;
      a=z+x+y;
      cout<<"Keliling Segitiga     = "<<a<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if (no==7)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"  =*= Keliling Persegi =*=    "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Nilai Sisi = "; cin>>a;
      cout<<endl;
      cout<<"Keliling Persegi    = 4 * "<<a<<endl;
      b=4*a;
      cout<<"Keliling Persegi    = "<<b<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if(no==8)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"   =*= Keliling Lingkaran =*=     "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Jari - Jari = "; cin>>a;
      cout<<endl;
      cout<<"Keliling Lingkaran   = 3.14 * ( 2 * "<<a<<" )"<<endl;
      b=phi*(2*a);
      cout<<"Keliling Lingkaran   = "<<b<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;  cout<<endl;
      }

      if (no==9)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<" =*= Keliling Belah Ketupat =*=   "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Sisi Pertama  = "; cin>>x;
      cout<<"Masukkan Sisi Kedua    = "; cin>>y;
      cout<<"Masukkan Sisi Ketiga   = "; cin>>z;
      cout<<"Masukkan Sisi Keempat  = "; cin>>a;
      cout<<endl;
      cout<<"Keliling Belah Ketupat = "<<x<<" + "<<y<<" + "<<z<<" + "<<a<<endl;
      b=a+x+y+z;
      cout<<"Keliling Belah Ketupat = "<<b<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if (no==10)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"  =*= Keliling Trapesium =*=   "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Sisi Pertama  = "; cin>>x;
      cout<<"Masukkan Sisi Kedua    = "; cin>>y;
      cout<<"Masukkan Sisi Ketiga   = "; cin>>z;
      cout<<"Masukkan Sisi Keempat  = "; cin>>a;
      cout<<endl;
      cout<<"Keliling Trapesium     = "<<x<<" + "<<y<<" + "<<z<<" + "<<a<<endl;
      b=a+x+y+z;
      cout<<"Keliling Trapesium     = "<<b<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }
      system ("pause");
      system ("cls");
      goto lagi;
   }

      dasar:
   {
       clrscr();
      cout<<"==============================="<<endl;
      cout<<"        Matematika Dasar       "<<endl;
      cout<<"==============================="<<endl;
      cout<<endl;
      cout<<" =*= PILIHAN PROGRAM =*= "<<endl<<endl;
      cout<<" 1. Penjumlahan "<<endl;
      cout<<" 2. Pengurangan "<<endl;
      cout<<" 3. Perkalian "<<endl;
      cout<<" 4. Pembagian "<<endl;
      cout<<" 5. Tabel Perkalian"<<endl;
      cout<<" 6. Akar Kuadrat"<<endl<<endl;
      cout<<endl;
      cout<<"Masukkan Pilihan Program = "; cin>>no;
      cout<<endl;
      if(no==1)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"  =*= Program Penjumlahan =*=  "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Nilai a  = "; cin>>a;
      cout<<"Masukkan Nilai b  = "; cin>>b;
      cout<<endl;
      c=a+b;
      cout<<"Hasil Penjumlahan = "<<c<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if(no==2)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"  =*= Program Pengurangan =*=  "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Nilai a  = "; cin>>a;
      cout<<"Masukkan Nilai b  = "; cin>>b;
      cout<<endl;
      c=a-b;
      cout<<"Hasil Pengurangan = "<<c<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if (no==3)
      {
      clrscr();
      cout<<"-------------------------------"<<endl;
      cout<<"   =*= Program Perkalian =*=   "<<endl;
      cout<<"-------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Nilai a  = "; cin>>a;
      cout<<"Masukkan Nilai b  = "; cin>>b;
      cout<<endl;
      c=a*b;
      cout<<"Hasil Perkalian = "<<c<<endl;
      cout<<endl;
      cout<<"-------------------------------";
      cout<<endl;   cout<<endl;
      }

      if (no==4)
      {
      clrscr();
      cout<<"------------------------------"<<endl;
      cout<<"  =*= Program Pembagian =*=   "<<endl;
      cout<<"------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Nilai a  = "; cin>>a;
      cout<<"Masukkan Nilai b  = "; cin>>b;
      cout<<endl;
      cout.setf(ios::fixed);
      cout.precision(2);
      c=a/b;
      cout<<"Hasil Pembagian   = "<<c<<endl;
      cout<<endl;
      cout<<"------------------------------"<<endl;
      cout<<endl; cout<<endl;
      }

      if (no==5)
      {
      clrscr();
      cout<<"------------------------------"<<endl;
      cout<<"=*= Tabel Perkalian 1 - 10 =*="<<endl;
      cout<<"------------------------------"<<endl;
      cout<<endl;
      cout<<"Masukkan Angka Perkalian = "; cin>>c ;
      cout<<endl;
      for (a=c; a<=c; a++)
        {

        for (b=1; b<= 10;++b)
        cout<<a<<" x "<<b<<" = "<<a*b<<"\n"<<endl;
      cout<<"------------------------------"<<endl;

        }
      cout<<endl<<endl;
      }

      if (no==6)
      {
      clrscr();
      cout<<"------------------------------"<<endl;
      cout<<"     =*= Akar Kuadrat =*=     "<<endl;
      cout<<"------------------------------"<<endl;
      cout<<endl;
        cout<<"Masukkan Angka : "; cin>>a;
        cout<<endl<<endl;
         cout<<"Akar Dari "<<a<<" = "<<sqrt(a)<<endl<<endl;
      cout<<"------------------------------"<<endl;
      cout<<endl<<endl;
      }
      system ("pause");
      system ("cls");
      goto lagi;
   }
      lagi:

      cout<<" ------------------------ PILIHAN ----------------------"<<endl;
        cout<<" |  [1] Masuk Dengan User Lain                         |"<<endl;
        cout<<" |  [2] Menu Utama                                     |"<<endl;
      cout<<" |  [3] Keluar                                         |"<<endl;
      cout<<" -------------------------------------------------------"<<endl<<endl;

    cout<<" Silahkan masukkan pilihan anda : ";
    cin>>pil;
   system ("cls");

   if (pil==1)
       { goto user; }
   else if (pil==3)
       keluar:
       {
           cout<<endl; cout<<endl;
           system ("cls");
           cout<<"=*= Terimakasih Mr. "<<nama<<" =*= "<<endl;
           cout<<endl;
           cout<<"                             By : mr. kadoel "<<endl;
           cout<<"                             --------------- "<<endl;
   }
  else if (pil==2)
          { goto milihmenu;}
   else
       { system("cls");  goto lagi; }
   getch();
}
===================================================

Print Outnya Gan :










Atau download Source Codenya di SINI

 Semoga Bermanfaat Gan....

Read this | Baca yang ini



Widget by [ Free Widget ]

2 comments:

Adis | Dunia Teknologi mengatakan...

Makin mantap aja codingnya gan.. Moga jadi master dalam bahasa C++

Looser Senosci mengatakan...

Masih tahap Belajar gan... Untuk jadi master kyaknya susah sekali... tapi astungkara...

Posting Komentar

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Cheap Web Hosting