Electricity bill program in C
In this article, we will create a program to calculate an electricity bill in C.
The output of the program will show the bill amount in rupees:
Example 1: Enter the number of units consumed: 150 Electricity Bill Amount: Rs. 1125.00 Example 2: Enter the number of units consumed: 50 Electricity Bill Amount: Rs. 375.00 Example 3: Enter the number of units consumed: 0 Electricity Bill Amount: Rs. 0.00
In this program, we define the unit and tax rates as constants using the #define directive. The calculate bill function takes the number of units consumed as an argument and calculates the bill amount by multiplying the units with the unit rate. It also calculates the tax amount based on the tax rate and adds it to the bill amount.
In the main Function, we prompt the user to enter the number of units consumed using printf and scanf. After that, we call the calculateBill Function to calculate the total bill amount. Finally, we display the bill amount using printf.
Please note that it is a basic and plain example, and it does not include input validation or additional features like customer information or bill payment options. You can enhance the program according to your requirements.
Algorithm of the above program:
Here's the algorithm of the electricity bill program:
This algorithm outlines the steps taken in the program to calculate and display the electricity bill amount based on the user input.
To calculate the bill based on the given inputs and predefined rates, you can use the following formula:
billAmount is the total bill amount (including tax).
units is the number of units consumed by the user.
UNIT_RATE is the predefined rate per unit consumed.