# C++ | Create a Electricity bill

Introduction

This program calculates the bill for electricity according to given instructions . This program is to print the bill. The program can be extended by adding more instructions and more rates or additional charges and adding them to final amount. Go enjoy the program. Lets begin………..

Instructions

Take the units consumed
Accordingly calculate amt
for 1st 100 units @ 1Rs.(any currency)/unit
for next 100 units @ 2 Rs./unit
for next 100 units @ 3 Rs./unit
for next 200 units @ 4 Rs./unit
for next units @ 5 Rs./unit
tax to be added in final amount @ 10%.
Meter charge 50 Rs. extra.
Print the bill….

Program to create the bill for electricity

``````
#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen
clrscr();
//declare uc variable as int
int uc;
//declare variables as float
float amt,famt,tax;
//Input the units consumed
cout<<"Enter the units consumed by the consumer"<<endl;
cin>>uc;
//conditional statement
if(uc>=0 && uc<=100)
amt=uc*1;
else
{
if(uc>100 && uc<=200)
amt=((uc-100)*2)+100;
else
{
if(uc>200 && uc<=300)
amt=((uc-200)*3)+300;
else
{
if(uc>300 && uc<=500)
amt=((uc-300)*4)+600;
else
amt=((uc-500)*5)+1400;
}
}
}
//calculate tax and final amount
tax=(amt*10)/100;
famt=amt+50+tax;
//print the bill
cout<<"---------------------------"<<endl;
cout<<" Bill "<<endl;
cout<<"---------------------------"<<endl;
cout<<"Bill of units "<<amt<<endl;
cout<<"Meter charges 50"<<endl;
cout<<"Tax "<<tax<<endl;
cout<<"---------------------------"<<endl;
cout<<"Total bill "<<famt<<endl;
cout<<"---------------------------"<<endl;
//get character
getch();
}
``````

Output

Enter the units consumed by the consumer
650
—————————
Bill
—————————
Bill of units           2150
Meter charges     50
Tax                          215
—————————
Total bill               2415
—————————

How does it work

1. You enter the units consumed in and is saved in variable.
2. Calculates the amt according to given instructions.
3. Calculates the tax.
4. Calculates the final amount.
5. Prints the bill.

Extending it

The program can be extended by adding more instruction to the program or additional charges. Add them to the final amount. Then print the bill.

Explanation.

1. Include ‘iostream.h’ and ‘conio.h’ files.
3. Start program by first clearing the screen.
4. Declare the variables as int or float (name them as you want.)
5. Add cout and cin of variable of input of units consumed.(as shown in program)
6. Add the conditional statement if-else that calculates amt.
7. Calculate the tax and save it it in ‘tax’ variable.
8. Calculate the final amount and save it in ‘famt’ variable.
9. Print the bill.

At the end

You learnt creating the c++ program of creating the electricity bill. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Sharing options: