Here, we have a basic program example to calculate the electricity bill using different languages. The charge are as follow : Unit Charge/unit
upto 199 @1.20
200 and above but less than 400 @1.50
400 and above but less than 600 @1.80
600 and above @2.00
If bill exceeds Rs. 400 then a surcharge of 15% will be charged and the minimum bill should be of Rs. 100/-
This program is created in c language, c++, Java, and Python.
Program to calculate electricity bill in C language
#include <stdio.h>
#include <string.h>
void main()
{
int cust_id, unit_consumed;
float charge, sur_charge=0, gramt,net_amt;
char cust_name[25];
printf("Input Customer ID :");
scanf("%d",&cust_id);
printf("Input the name of the customer :");
scanf("%s",&cust_name);
printf("Input the unit consumed by the customer : ");
scanf("%d",&unit_consumed);
if (unit_consumed <200 )
charge = 1.20;
else if (unit_consumed>=200 && unit_consumed<400)
charge = 1.50;
else if (unit_consumed>=400 && unit_consumed<600)
charge = 1.80;
else
charge = 2.00;
gramt = unit_consumed*charge;
if (gramt>300)
sur_charge = gramt*15/100.0;
net_amt = gramt+sur_charge;
if (net_amt < 100)
net_amt =100;
printf("\nElectricity Bill\n");
printf("Customer IDNO :%d\n",cust_id);
printf("Customer Name :%s\n",cust_name);
printf("unit Consumed :%d\n",unit_consumed);
printf("Amount Charges @Rs. %4.2f per unit :%8.2f\n",charge,gramt);
printf("Surchage Amount :%8.2f\n",sur_charge);
printf("Net Amount Paid By the Customer :%8.2f\n",net_amt);
}
Program to calculate electricity bill in C++ language
#include<iostream>
using namespace std;
int main()
{
int cust_id, unit_consumed;
float charge, sur_charge=0, gramt,net_amt;
char cust_name[25];
cout<<"Input Customer ID :";
cin>>cust_id;
cout<<"Input the name of the customer :";
cin>>cust_name;
cout<<"Input the unit consumed by the customer : ";
cin>>unit_consumed;
if (unit_consumed <200 )
charge = 1.20;
else if (unit_consumed>=200 && unit_consumed<400)
charge = 1.50;
else if (unit_consumed>=400 && unit_consumed<600)
charge = 1.80;
else
charge = 2.00;
gramt = unit_consumed*charge;
if (gramt>300)
sur_charge = gramt*15/100.0;
net_amt = gramt+sur_charge;
if (net_amt < 100)
net_amt =100;
cout<<"\nElectricity Bill\n";
cout<<"Customer IDNO :"<<cust_id<<endl;
cout<<"Customer Name :"<<cust_name<<endl; cout<<"unit Consumed :"<<unit_consumed<<endl;
cout<<"Amount Charges @Rs."<<charge<<"per unit :"<<gramt<<endl;
cout<<"Surcharge Amount :"<<sur_charge<<endl;
cout<<"Net Amount Paid By the Customer :"<<net_amt<<endl;
}
Program to calculate electricity bill in Python language
cust_id=int(input("Input Customer ID :"))
cust_name = input("Input the name of the customer :")
unit_consumed=int(input("Input the unit consumed by the customer : "))
if(unit_consumed<200):
charge=1.20
elif(unit_consumed>=200 and unit_consumed<400):
charge=1.50
elif(unit_consumed>=400 and unit_consumed<600):
charge=1.80
else:
charge=2.00
gramt = unit_consumed*charge
if(gramt>300):
sur_charge=gramt*15/100.0
net_amt = gramt+sur_charge
if(net_amt<100):
net_amt=100
print("ELECTRICITY BILL")
print("Customer Id Number : ", cust_id)
print("Customer Name : ", cust_name)
print("Unit Consumed : ", unit_consumed)
print("Amount Charges @Rs.",charge," per unit : ",gramt)
print("Surcharge Amount : ", sur_charge)
print("Net Amount Paid By the Customer : ", net_amt)
Program to calculate electricity bill in Java language
import java.util.*;
public class electricity {
public static void main(String[] args) {
int cust_id, unit_consumed;
double charge, sur_charge=0, gramt,net_amt;
Scanner s=new Scanner(System.in);
System.out.println("Input Customer ID : ");
cust_id = s.nextInt();
System.out.println("Input the name of the customer : ");
String cust_name = s.nextLine();
System.out.println("Input the unit consumed by the customer : ");
unit_consumed = s.nextInt();
if (unit_consumed <200 )
charge = 1.20;
else if (unit_consumed>=200 && unit_consumed<400)
charge = 1.50;
else if (unit_consumed>=400 && unit_consumed<600)
charge = 1.80;
else
charge = 2.00;
gramt = unit_consumed*charge;
if (gramt>300)
sur_charge = gramt*15/100.0;
net_amt = gramt+sur_charge;
if (net_amt < 100)
net_amt =100;
System.out.println("Electricity Bill");
System.out.println("Customer IDNO :"+ cust_id);
System.out.println("Customer Name :"+ cust_name);
System.out.println("unit Consumed :"+ unit_consumed);
System.out.println("Amount Charges @Rs." + charge + "per unit :" + gramt);
System.out.println("Surchage Amount :"+ sur_charge);
System.out.println("Net Amount Paid By the Customer :"+ net_amt);
}
}