Senin, 09 Juli 2012

contoh bahasa C dasar

#include<stdio.h>
#include<conio.h>
void main(){
int Pilih;
int kode,jml,a,kode2[10],jumlah [10];
float harga[10],total[10],tot,diskon[10],kembali,bayar;
char nama[10][20];
float bil1,bil2,hasil;
char op,ulang;
clrscr();
printf("====================================\n");
printf("             MENU PROGRAM\n");
printf("====================================\n");
printf("\n1. KASIR");
printf("\n2. KALKULATOR");
printf("\n3. DATA KASIR");
printf("\n4. KELUAR");
printf("\n\nPilihan Anda [1-4] : ");
scanf("%d",&Pilih);
switch(Pilih){
case 1 :
//--------------------------------------//
do
{
clrscr();
printf ("kode kasir :");
scanf ("%d",&kode);
if (kode==1)
printf ("nama kasir : SUHERMAN\n");
else if (kode==2)
printf ("nama kasir : SUTIYEM\n");
else     if (kode==3)
printf ("nama kasir : SUBEJO\n");
else
printf ("nama kasir : OWNER\n");
printf("====================================\n");
do
{
printf ("masukan jumlah barang yang di beli:");
scanf ("%d",&jml);
}while(jml>10);
a=0;tot=0;
do
{
printf ("barang ke-%d:\n",a+1);
printf("kode barang    :");
scanf("%d",&kode2[a]);
printf("nama barang    :");
scanf("%s",nama[a]);
printf("harga barang   :");
scanf("%f",&harga[a]);
printf("jumlah barang  :");
scanf("%d",&jumlah[a]);
total[a]=(harga[a]*jumlah[a]);
printf("total          =%.2f\n",total[a]);
tot=tot+total[a];
a++;
}while (a<jml);
printf("====================================\n");
printf ("\nTOTAL HARGA          :%.2f",tot);
printf ("\njumlah yang di bayar :");
scanf ("%f",&bayar);
kembali=bayar-tot;
printf("====================================\n");
printf ("\n kembalian           :%.2f\n",kembali);
printf("====================================\n");
printf("\n\n APAKAH INGIN TRANSAKSI ULANG (y/t) = "); scanf("%s",&ulang);
}
while (ulang=='y');
break;
//---------------------------------------------//
case 2 :
do
{
clrscr ();
printf("====================================\n");
printf("             KALKULATOR\n");
printf("====================================\n");
printf("bilangan 1         ="); scanf("%f", &bil1);
printf("bilangan 2         ="); scanf("%f", &bil2);
printf("operasi(+,-,/,*)   ="); scanf("%s", &op);
printf("_______________________-\n");
if(op=='+') hasil = bil1 + bil2 ;
else if(op=='-') hasil = bil1 - bil2;
else if(op=='*') hasil = bil1 * bil2;
else if(op=='/') hasil = bil1 / bil2;
printf("hasil             = %0.2f", hasil);
printf("\n\n APAKAH INGIN MENHITUNG LAGI ? (y/t) = "); scanf("%s",&ulang);
}
while (ulang=='y');
break;
//----------------------------------------------//
case 3 :
do {
clrscr();
printf ("masukan kode kasir :");
scanf ("%d",&kode);
if (kode==1){
printf("====================================\n");
printf("       DATA PRIBADI KASIR\n");
printf("====================================\n");
printf ("NAMA   : SUHERMAN\n");
printf ("ALAMAT : JLN BUKU NO.1\n");
printf ("NO.HP  : 08133345444\n");
printf ("NO.KTP : 00808899898\n");}
else if (kode==2){
printf("====================================\n");
printf("       DATA PRIBADI KASIR\n");
printf("====================================\n");
printf ("NAMA   : SUTIYEM\n");
printf ("ALAMAT : JLN ISTANA NO.1\n");
printf ("NO.HP  : 081232325444\n");
printf ("NO.KTP : 008082323239898\n");}
else if (kode==3){
printf("====================================\n");
printf("        DATA PRIBADI KASIR\n");
printf("====================================\n");
printf ("nama kasir : SUBEJO\n");
printf ("ALAMAT     : JLN BREDE NO.1\n");
printf ("NO.HP      : 08230005444\n");
printf ("NO.KTP     : 008089999898\n");}
else{
printf("====================================\n");
printf("         DATA SUPERMARKET\n");
printf("====================================\n");
printf ("NAMA   : SUPERMAKET BIG\n");
printf ("ALAMAT : JLN SEJAHTERA NO.1\n");
printf ("NO.HP  : 0813333333\n");
printf ("NO.KTP : xxxxxxxx\n");}
printf("\n\n INGIN MEMBUKA YANG LAIN? (y/t) = "); scanf("%s",&ulang);
}
while (ulang=='y');
break;
//---------------------------------------------//
case 4 : exit(0);
default : printf("\n\nANDA SALAH INPUT...");
}
getch();
return 0;
}

Tidak ada komentar:

Posting Komentar