Jumat, Maret 14, 2014
0


Materi : latihan case dan if

#include <stdio.h>
#include <conio.h>
#include <iostream.h>
main()
{

 char nama[20],lagi;
 int kode,jumlah,jumbel,harga;
 float diskon,total;
 atas:
 clrscr();
 cout<<"\t\tTOKO ELEKTRONIK XYZ\n";
 cout<<"\t\t===================\n";
 cout<<"\nMasukkan Kode Barang [1/2/3] : ";cin>>kode;
 switch(kode)
 {
  case 1:
  strcpy(nama,"Televisi");
  harga=800000;
  break;
  case 2:
  strcpy(nama,"Radio");
  harga=400000;
  break;
  default:
  strcpy(nama,"Kulkas");
  harga=500000;
 }
 cout<<"\n\nnama Barang            : "<<nama;
 cout<<"\n\nHarga                  : "<<harga;
 cout<<"\n\nMasukkan Jumlah Barang : ";cin>>jumlah;
 cout<<"\n\n======================================";
 jumbel=harga*jumlah;
 cout<<"\n\nJumlah Pembelian       : "<<jumbel;

 if(jumlah>10)
  {
   diskon=0.15*jumbel;
  }
  else
   {
   diskon=0.05*jumbel;
   }

  printf("\n\nDiskon                 : %8.2f",diskon);
  total=jumbel-diskon;
  printf("\n\nTotal                  : %8.2f\n",total);
  //printf("\nAkan input lagi ?");scanf("%c",&lagi);
  cout<<"Ingin input lagi ?";cin>>lagi;

  if(lagi=='y'||lagi=='Y')
            goto atas;

 getch();

}
Next
This is the most recent post.
Posting Lama

0 komentar:

Posting Komentar