#include <stdio.h>
int main()
{
int hrgsat, jmlbrg, total, kode;
float disc;
char jwb;
label1:
printf("===========================================");
printf("\nMasukkan harga satuan = Rp ");scanf("%d", &hrgsat);
printf("Masukkan jumlah barang = ");scanf("%d", &jmlbrg);
total=jmlbrg*hrgsat;
if (jmlbrg<=10) kode=1;
if (jmlbrg>10 && jmlbrg<=20) kode=2;
if (jmlbrg>20 && jmlbrg<=50) kode=3;
if (jmlbrg>50) kode=4;
switch (kode)
{
case 1:
{
disc=0;
total=total-disc;
printf("\n================================");
printf("\nAnda tidak dapat diskon");
printf("\nTotal Pembayaran = Rp %d", total);
printf("\n================================");
break;
}
case 2:
{
disc=total*0.05;
total=total-disc;
printf("\n================================");
printf("\nDiskon sebesar 5 persen");
printf("\nTotal Pembayaran = Rp %d", total);
printf("\n================================");
break;
}
case 3:
{
disc=total*0.1;
total=total-disc;
printf("\n================================");
printf("\nDiskon sebesar 10 persen");
printf("\nTotal Pembayaran = Rp %d", total);
printf("\n================================");
break;
}
case 4:
{
disc=total*0.15;
total=total-disc;
printf("\n================================");
printf("\nDiskon sebesar 15 persen");
printf("\nTotal Pembayaran = Rp %d", total);
printf("\n================================");
break;
}
}
printf("\n\nApakah anda ingin mencoba lagi (Y/T)? ");
scanf("%s",&jwb);
if ((jwb=='Y')||(jwb=='y'))
{
printf("\n\n");
goto label1;
}
else
{
printf("\nTerima kasih");
}
return 0;
}
https://indahabni.blogspot.com/2011/10/include-int-main-int-hrgsat-jmlbrg.html
int main()
{
int hrgsat, jmlbrg, total, kode;
float disc;
char jwb;
label1:
printf("===========================================");
printf("\nMasukkan harga satuan = Rp ");scanf("%d", &hrgsat);
printf("Masukkan jumlah barang = ");scanf("%d", &jmlbrg);
total=jmlbrg*hrgsat;
if (jmlbrg<=10) kode=1;
if (jmlbrg>10 && jmlbrg<=20) kode=2;
if (jmlbrg>20 && jmlbrg<=50) kode=3;
if (jmlbrg>50) kode=4;
switch (kode)
{
case 1:
{
disc=0;
total=total-disc;
printf("\n================================");
printf("\nAnda tidak dapat diskon");
printf("\nTotal Pembayaran = Rp %d", total);
printf("\n================================");
break;
}
case 2:
{
disc=total*0.05;
total=total-disc;
printf("\n================================");
printf("\nDiskon sebesar 5 persen");
printf("\nTotal Pembayaran = Rp %d", total);
printf("\n================================");
break;
}
case 3:
{
disc=total*0.1;
total=total-disc;
printf("\n================================");
printf("\nDiskon sebesar 10 persen");
printf("\nTotal Pembayaran = Rp %d", total);
printf("\n================================");
break;
}
case 4:
{
disc=total*0.15;
total=total-disc;
printf("\n================================");
printf("\nDiskon sebesar 15 persen");
printf("\nTotal Pembayaran = Rp %d", total);
printf("\n================================");
break;
}
}
printf("\n\nApakah anda ingin mencoba lagi (Y/T)? ");
scanf("%s",&jwb);
if ((jwb=='Y')||(jwb=='y'))
{
printf("\n\n");
goto label1;
}
else
{
printf("\nTerima kasih");
}
return 0;
}