Ini contoh program untuk percabangan. Program Rental Kendaraan.
#include <stdio.h>
#include <stdlib.h>
float x;
int hrg;
int hari;
int tipe;
int main(int argc, char *argv[])
{
printf("HARGA RENTAL KENDARAAN \n");
printf("====================== \n");
printf("1. AVP \n");
printf("2. SEDAN \n");
printf("3. SUV \n");
printf("====================== \n");
printf ("Masukkan Nomor Jenis Kendaraan Yang Anda Pilih : "); scanf("%d",&tipe);
switch (tipe)
{
case 1:
{
printf ("Lama Sewa : "); scanf("%d",&hari);
printf ("================================");
if (hari <= 3)
{
hrg = 500000;
x = hari * hrg;
printf("========================\n");
printf("Jenis Kendaraan : AVP\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
else
{
hrg = 400000;
x = hari*hrg;
printf("Jenis Kendaraan : AVP\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
break;
}
case 2:
{
printf ("Lama Sewa : "); scanf("%d",&hari);
printf ("================================\n");
if (hari <= 3)
{
hrg = 600000;
x = hari*hrg;
printf("Jenis Kendaraan : SEDAN\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
else
{
hrg = 450000;
x = hari*hrg;
printf("Jenis Kendaraan : SEDAN\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
break;
}
case 3:
{
printf ("Lama Sewa : "); scanf("%d",&hari);
printf ("================================\n");
if (hari <= 3)
{
hrg = 700000;
x = hari*hrg;
printf("Jenis Kendaraan : SUV\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
else
{
hrg = 550000;
x = hari*hrg;
printf("Jenis Kendaraan : SUV\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
break;
}
default:
{
printf("Jenis Kendaraan Salah(Pilih Nomor Menu Kendaraan)");
break;
}
}
system("PAUSE");
return 0;
}
++++Belajar lah saat anda bugar. dan berhentilah ketika anda lelah. BELAJAR++++
No comments:
Post a Comment