1 / 8

PERTEMUAN 4

PERTEMUAN 4. S eleksi Kondisi. If Sederhana. [Kristanto:2009] perintah if berguna untuk memilih satu dari 2 atau lebih alternatif jaw a ban yang tersedia. Jika perintah if tersebut terdiri dari 2 atau lebih pernyataan . Bentuk Umum: if (kondisi) { pernyataan }.

kynan
Download Presentation

PERTEMUAN 4

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. PERTEMUAN 4 SeleksiKondisi

  2. If Sederhana [Kristanto:2009] perintah if berguna untuk memilih satu dari 2 atau lebih alternatif jawaban yang tersedia. Jika perintah if tersebut terdiri dari 2 atau lebih pernyataan. Bentuk Umum: if (kondisi) { pernyataan }

  3. #include <iostream.h> #include <conio.h> main() { intharga,diskon=0; char bonus[10]; cout<<" \2\2\2\3\3\3\3\2\2\2\2"<<endl; cout<<" Input Harga : ";cin>>harga; if(harga>10000) { diskon=0.10*harga; strcpy(bonus,"Permen"); } clrscr(); cout<<" HargaBeli : "<<harga<<endl; cout<<" Diskon : "<<diskon<<endl; cout<<" Bonus : "<<bonus; getch(); }

  4. Perintah If...Else BentukUmum: if(kondisi) pernyataan1 else pernyataan2

  5. #include <iostream.h> #include <conio.h> main() { intharga,diskon=0; char bonus[10]; cout<<" \2\2\2\3\3\3\3\2\2\2\2"<<endl; cout<<" Input Harga : ";cin>>harga; if(harga<10000) {diskon=0.10*harga; strcpy(bonus,"Permen"); } else {diskon=0.20*harga; strcpy(bonus,"Coklat"); } clrscr(); cout<<" HargaBeli : "<<harga<<endl; cout<<" Diskon : "<<diskon<<endl; cout<<" Bonus : "<<bonus; getch(); }

  6. Perintah If...ElseMajemuk if (kondisi) { perintah-1; ... } else { perintah-2; ... }

  7. Contoh: if(gol=='1') { strcpy(jab,"Direktur"); gapok=5000000; } else if(gol=='2') { strcpy(jab,"Manajer"); gapok=4000000; } cout<<" Jabatan = "<<jab<<endl cout<<" GaPok="<<gapok<<endl; getch ( ); } #include <stdio.h> #include <conio.h> #include <iostream.h> main( ) { char gol, jab[10]; long gapok=0; clrscr( ); cout<<endl<<" Data Jabatan"<<endl <<" = = = = = = = = = = = = ="<<endl; cout<<" Masukan Golongan [1/2]:"; cin>>gol;

  8. Input: Output: Ketentuan Soal total=pend+komisi+jasa;

More Related