1 / 20

PENGAMBILAN KEPUTUSAN

PENGAMBILAN KEPUTUSAN. 3. Operator Logika. Logika AND  True AND True = True True AND False = False False AND True = False False AND False = False.

feivel
Télécharger la présentation

PENGAMBILAN KEPUTUSAN

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. PENGAMBILAN KEPUTUSAN

  2. 3. Operator Logika Logika AND  True AND True = True True AND False = FalseFalse AND True = False False AND False = False

  3. Logika OR  True OR True = TrueTrue OR False = TrueFalse OR True = True False OR False = False OR AND

  4. Statement IF a. Bentuk If Tunggal sintak penulisan: if cond_expression { True expression } Jika cond_expr salah, maka….. true statement akan diabaikan. Jika cond_expr benar, maka…. true statement akan dieksekusi

  5. b. Bentuk If dengan else sintak penulisan: if cond_expression { true_statement } else { false statement } Jika cond_expr benar makatrue statement akan dijalankan Jika cond_expr salah makaeksekusi program tertuju pada false statement

  6. c. Bentuk If Bersarang (Nested If)  bentuk stat.if dengan stat.if lain di dalamnya.  sintaks penulisan: if cond_exprA { if cond_exprB { true statementB ;} else { false statementB } } { False statementB }

  7. d.Statement Switch  Stat.yg dimanfaatkan untuk menentukan pilihan dari sejumlah pilihan yang terlibat.  Mempunyai 2 bentuk 1. Swicth Tunggal 2. Switch Bersarang

  8.  Sintaks penulisan: switch cond_expr { case konstanta1: { statemen2;break } case konstanta1: { statemen2;break } case konstanta1: { statemen2;break } - - - - - default { statement-statemen } }

  9. CONTOH PROGRAM #include <stdio.h> #include <conio.h> #include <iostream.h> void main () { float ipk;

  10. // I. Menggunakan printf dan scanf // /* printf("Isikan nilai IPK ="); scanf("%f",&ipk); if (ipk>2.75) printf("Selamat Anda Lulus"); else printf("Maaf...Anda gagal"); getch(); */

  11. // II. Menggunakan Cout dan Cin cout <<"Isikan nilai IPK =";cin>>ipk; if (ipk > 2.75) { cout <<"Selamat Anda Lulus"; } else cout <<"Maaf...Anda gagal"; getch(); }

  12. Buatlah program untuk menentukan bilangan genap atau ganjil. • Gunakan statement IF dengan Else. • Simpan program dengan nama Kuis_XXXX  XXXX = NIM ke folder

  13. Contoh statement nested if #include <stdio.h> #include <conio.h> void main() { float nilai; // menggunakan printf dan scanf printf ("Isikan Nilai Anda ="); scanf ("%f",&nilai);

  14. if ((nilai >0) && (nilai <=100)) if (nilai >=60) { printf ("Anda lulus"); } else { printf ("Maaf...Anda tidak lulus"); } else printf ("Salah nilai");//else if1 getch(); }

  15. { printf ("Maaf...Anda tidak lulus"); } else printf ("Salah nilai"); getch( ); }

  16. LATIHAN • Analisis program nilai (di atas) • Buat program untuk menentukan nilai: A = nilai 90 – 100 B = nilai 70 – 89 C = nilai 60 – 69 D = nilai 50 – 59 E = nilai kurang dari 50

  17. Contoh Percabangan dgn switch //PROGRAM KONVERSI NILAI HURUF #include <conio.h> #include <iostream.h> #include <stdio.h> void main() { char nilai_huruf; int nilai_angka;

  18. printf ("PROGRAM KONVERSI NILAI\n"); printf ("\nNIlai Huruf ="); scanf ("%c",&nilai_huruf); switch (nilai_huruf) { case 'A' : nilai_angka = 4;break; case 'B' : nilai_angka = 3;break; case 'C' : nilai_angka = 2;break; case 'D' : nilai_angka = 1;break; case 'E' : nilai_angka = 0;break; default :printf("Nilai yang dimasukkan salah"); }

  19. if ( nilai_huruf >= 'A‘ && nilai_huruf <= 'E‘ ) printf ("Nilai Anda %i\n",nilai_angka); getch( ); }

  20. LATIHAN • Buat program menentukan nama bulan • Input  angka (untuk lihat nama bulan) • Output  nama bulan berdasarkan input • Contoh : (input) Memilih Bulan ke = 4 <enter> (output) Bulan April

More Related