Home » , » contoh menghitung KWH dengan bahasa C

contoh menghitung KWH dengan bahasa C

Posted by Tutorial Programming on Senin, 02 April 2012



Algoritma & Flowchart


Input :
  • Pilih kelas
  • Masukkan total kWH
  • Mempunyai kartu gkin apa tidak (Y/T)
Output : Total bayar
Proses :
  • Jika 1=kelas1, 2=kelas2, 3=kelas3
  • Jika mempunyai gakin abonemen di potong 50%
  • Jika tidak maka abonemen tetap

Script
#include<stdio.h>
void main()
{
double kWH,kelas,total,x,y,y1,z,z1;
char gakin;

printf("pilih kelas : ");
scanf("%lf",&kelas);

printf("Masukan total kWH : ");
scanf("%lf",&kWH);

if(kelas==1)
{
printf("\n Abonemen Kelas 1");
printf("\n jika anda mempunyai kartu GAKIN");
printf("\n ketik 1=YA ketik 0=TIDAK\n ");
scanf("%d",&gakin);

if(gakin==1)
{
x=25*1000;
if(kWH<=100)
{
total=300+(x*0.5);
printf(" total harga : %0.2lf",total);
}
else if(kWH<=200)
{
total=(kWH-100)+500+(x*0.5);
printf(" total harga : %0.2lf",total);
}
else if(kWH>200)
{
total=(kWH-200)+1000+(x*0.5);
printf(" total harga : %0.2lf",total);
}
else
{
printf(" KODE ERROR ");
}
}
else if(gakin==0)
{
x=25*1000;
if(kWH<=100)
{
total=300+x;
printf(" total harga : %0.2lf",total);
}
else if(kWH<=200)
{
total=(kWH-100)+500+x;
printf(" total harga : %0.2lf", total);
}
else if(kWH>200)
{
total=(kWH-200)+1000+x;
printf(" total harga : %.lf", total);
}
else
{
printf("\n KODE ERROR ");
}
}
else
{
printf("\n KODE ERROR");
}
}
else if(kelas==2)
{
printf("\n Abonemen Kelas 2");
printf("\n jika anda mempunyai kartu GAKIN (Y/T): ");
printf("\n ketik 1=YA ketik 0=TIDAK\n ");
scanf("%d",&gakin);

if(gakin==1)
{
y1=35*10;
y=y1*100;
if(kWH<=100)
{
total=300+(y/2);
printf(" total harga : %0.2f",total);
}
else if(kWH<=200)
{
total=(kWH-100)+500+(y/2);
printf(" total harga : %0.2f",total);
}
else if(kWH>200)
{
total=(kWH-200)+1000+(y/2);
printf(" total harga : %0.2f",total);
}
}
else if(gakin==0)
{
y1=35*10;
y=y1*100;
if(kWH<=100)
{
total=300+y;
printf(" total harga : %0.2f",total);
}
else if(kWH<=200)
{
total=(kWH-100)+500+y;
printf(" total harga : %0.2f", total);
}
else if(kWH>200)
{
total=(kWH-200)+1000+y;
printf(" total harga : %.f", total);
}
}
else
{
printf("\n KODE ERROR");
}
}


else if(kelas==3)
{
printf("\n Abonemen Kelas 3");

printf("\n jika anda mempunyai kartu GAKIN (Y/T): ");
printf("\n ketik 1=YA ketik 0=TIDAK\n ");
scanf("%d",&gakin);

if(gakin==1)
{
z1=60*10;
z=z1*100;
if(kWH<=100)
{
total=300+(z*0.5);
printf(" total harga : %0.2f",total);
}
else if(kWH<=200)
{
total=(kWH-100)+500+(z*0.5);
printf(" total harga : %0.2f",total);
}
else if(kWH>200)
{
total=(kWH-200)+1000+(z*0.5);
printf(" total harga : %0.2f",total);
}
}
else if(gakin==0)
{
z1=60*10;
z=z1*100;
if(kWH<=100)
{
total=300+z;
printf(" total harga : %0.2f",total);
}
else if(kWH<=200)
{
total=(kWH-100)+500+z;
printf(" total harga : %0.2f", total);
}
else if(kWH>200)
{
total=(kWH-200)+1000+z;
printf(" total harga : %.f", total);
}
}
else
{
printf("\n KODE ERROR");
}
}
else
{
printf("\n KODE ERROR");
}
}


0 comments:

Posting Komentar