Sabtu, 22 Desember 2012

STRUKTUR LOOPING

STRUKTUR LOOPING

1.Buatlah program untuk menentukan total pembelian
minuman apabila diberlakukan ketentuan berikut ini:



Kode
Jenis Minuman
Harga
1
Milo
Rp 10.000,-
2
Kopi
Rp 3.000,-
3
Teh Manis
Rp 2.500,-
4
Jus
Rp 5.000,-

Kode Minuman diinputkan. Apabila total pembelian melebihi 100000,
maka akan mendapatkan potongan sebanyak 15%, sebaliknya jika
kurang dari 100000 tidak mendapatkan potongan

Bentuk Flowchart
















Listing program

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main( )
{                                                                                               
char kode,atas,lagi,minuman[15];
int qty;
float harga,jml,jml1,jml2,jml3,jml4,tot_harga,pot,hrg_bayar;
clrscr( );
cout<<"Pilihan Menu Minuman"<<endl;
printf("Kode\tJenis Minuman\tHarga");
printf("\n  1\t    Milo\tRp 10000");
printf("\n  2\t    Kopi\tRp 3000");
printf("\n  3\t  Teh Manis\tRp 2500");
printf("\n  4\t     Jus\tRp 5000");
atas:
cout<<endl;
cout<<"\nKode             : ";cin>>kode;
cout<<"Jumlah Pemesanan : ";cin>>qty;
if (kode=='1')
{strcpy(minuman,"Milo");
harga=10000;
jml1=harga*qty;
jml=jml1;}
else if (kode=='2')
{strcpy(minuman,"Kopi");
harga=3000;
jml2=harga*qty;
jml=jml2;}
else if (kode=='3')
{strcpy(minuman,"Teh Manis");
harga=2500;
jml3=harga*qty;
jml=jml3;}
else
{strcpy(minuman,"Jus");
harga=5000;
jml4=harga*qty;
jml=jml4;}
;
cout<<"Jenis Minuman    : "<<minuman<<endl;
cout<<"Jumlah Harga     : Rp "<<jml<<endl;
printf("Ingin Ulang Lagi[Y/T]:");
lagi=getche();
if(lagi=='Y'||lagi=='y')
goto atas;
cout<<endl;
cout<<"==========================="<<endl;
tot_harga=jml1+jml2+jml3+jml4;
cout<<"Total Harga      : Rp "<<tot_harga<<endl;
if(tot_harga>=100000)
   pot=0.15*tot_harga;
else
   pot=0;
cout<<"Potongan         : Rp "<<pot<<endl;
hrg_bayar=tot_harga-pot;
cout<<"Harga Bayar      : Rp "<<hrg_bayar;
getch();
}

Tampilan yang didapatkan


Tidak ada komentar:

Posting Komentar