Kamis, 03 Mei 2018

FUNGSI (FUNCTION)

TUGAS 11
1.
#include<conio.h>
#include<iostream>
#include<stdio.h>

using namespace std;

/* DEKLARASI FUNGSI potong */

/* DEKLARASI FUNGSI garis1 */

garis1(){
    cout<<"========================================"<<endl;
}
/* DEKLARASI FUNGSI garis2 */
garis2(){
    cout<<"-------------------------------------------"<<endl;
}
/* DEKLARASI FUNGSI space */
space(){
    cout<<endl;
}

        /* PROSES FUNGSI DISCOUNT (DISCOUNT = PRICE * DISCOUNT)*/
        potong(float price, float discount){
            return(price*discount);
        }


/* MAIN UTAMA */
int main()
{
    float p, d, t;
    //int t; for total bayar no printf %1.0f

        /* INPUT */
        space();
        garis2();
            cout<<" PROGRAM MENGHITUNG DISKON \"kamalmnop\" "<<endl;
        garis2();
            cout<<" Harga Barang                  Rp ";cin>> p;
        space();
/* DISCOUNT */
potong(p,d);
                /* IF - ELSE DISCOUNT */
                if (p <= 1000000)
                {
                    d = 0;
                }
                    else if (p >= 1000000)
                    {
                        d = p * 0.2;
                    }
                        if (p > 5000000)
                        {
                            d = p * 0.35;
                        }

        //cout<<" Diskon yang diberikan sebesar Rp "<< d <<endl;
        printf(" Diskon yang diberikan sebesar Rp %1.0f ",d);
        space();
/* TOTAL BAYAR = PRICE - DISCOUNT */
t = p - d;
        //cout<<" Total yang harus dibayar      Rp "<< t <<endl;
        printf(" Total yang harus dibayar      Rp %1.0f ",t);
      space();
    garis2();
  getch();
}//END MAINT UTAMA

OutPut:

Tidak ada komentar:

Posting Komentar