1 / 9

Contoh penggunaan goto

Contoh penggunaan goto. #include &lt;iostream.h&gt; #include &lt;conio.h&gt; #include &lt;iomanip.h&gt; main() { float p,l,luas,j; ulang: cout&lt;&lt;&quot;<br><br>Menghitung luas persegi<br><br>&quot;; cout&lt;&lt;&quot;Masukkan panjang (p)= &quot;;cin&gt;&gt;p; cout&lt;&lt;&quot;Masukkan lebar (l)= &quot;;cin&gt;&gt;l; luas=p*l;

floria
Download Presentation

Contoh penggunaan goto

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Contoh penggunaan goto #include <iostream.h> #include <conio.h> #include <iomanip.h> main() { float p,l,luas,j; ulang: cout<<"\n\nMenghitung luas persegi\n\n"; cout<<"Masukkan panjang (p)= ";cin>>p; cout<<"Masukkan lebar (l)= ";cin>>l; luas=p*l; cout<<"\nLuas persegi = "<<setiosflags(ios::fixed) <<setprecision(2) <<luas; cout<<endl;

  2. cout<<"\n\nAnda ingin menghitung lagi ?\n"; cout<<"\nJawab [1 = ya,0 = tidak ]: ";cin>>j; if(j==1) clrscr(); goto ulang; getch();}

  3. Contoh : #include <iostream.h> #include <conio.h> main() { int l,p,r,pil,t; float Luas,Kel; const float phi=3.14; bool jwb; cek: cout<<"Pilihan menu :\n"; cout<<"[1] Luas Lingkaran \n"; cout<<"[2] Luas Persegi \n"; cout<<"[3] Keliling Lingkaran \n"; cout<<"[4] Luas tabung\n\n";

  4. cout<<"Masukkan pilihan anda : ";cin>>pil; switch (pil){ case 1 : cout<<"Masukkan jari-jari : ";cin>>r; Luas=phi*(r*r); cout<<"\nLuas Lingkaran : "<<Luas<<endl<<endl; cout<<"Anda ingin pilih lagi?[1=ya,0=tdk] ";cin>>jwb; if(jwb==1) goto cek; else cout<<"Terima kasih"; break;

  5. case 2 : cout<<"Masukkan panjang : ";cin>>p; cout<<"Masukkan lebar : ";cin>>l; Luas=p*l; cout<<"\nLuas Persegi : "<<Luas<<endl<<endl; cout<<"Anda ingin pilih lagi?[1=ya,0=tdk] ";cin>>jwb; if(jwb==1) goto cek; else cout<<"Terima kasih"; break; case 3 : cout<<"Masukkan jari-jari : ";cin>>r; Kel=(phi*r)*2; cout<<"\nKeliling Lingkaran : "<<Kel<<endl<<endl;

  6. cout<<"Anda ingin pilih lagi?[1=ya,0=tdk] ";cin>>jwb; if(jwb==1) goto cek; else cout<<"Terima kasih"; break; case 4 : cout<<"Masukkan jari-jari:";cin>>r; cout<<"Masukkan tinggi: ";cin>>t; Luas=(phi*(r*r))*t; cout<<"\nKeliling Lingkaran : "<<Luas<<endl<<endl; cout<<"Anda ingin pilih lagi?[1=ya,0=tdk] ";cin>>jwb; if(jwb==1) goto cek; else cout<<"Terima kasih“; break;

  7. default : cout<<"Maaf pilihan menu yang anda inputkan tidak terdaftar ";} getch();}

  8. Tugas : • Menghitung gaji seseorang, diketahui : - gator = gapok+tunj+transport - pph = 5% dari gator - gaber = gator – pph - tunjangan hanya diberikan jika karyawan laki-laki dan sudah menikah. • Menghitung ipk mahasiswa • Buat flowchart dan implementasi programnya, menggunakan menu pilihan. Silahkan pilih struktur percabangannya

More Related