//Defining a function to compute the total bill amount
float computeTotalBill(int units) {
float totalAmount, taxValue;
// Determine the total bill value
totalBill = units * UNIT_RATE;
// Determine the total tax value
taxAmount = billAmount multiplied by the TAX_RATE;
// Increase the bill amount by adding the tax amount.
return billAmount;
}
int main {
int units;
float totalBill;
// Request user input for the quantity of units consumed
printf("Please input the total units consumed: ");
scanf("%d", &units);
// Compute the total amount of the bill
totalBill = determineBillAmount(units);
// Show the total amount of the electricity bill
printf("The total cost of the electricity bill is: $%.2f\n", totalBill);
return 0;
}
The output of the program will show the bill amount in rupees:
Illustration 1:
Input the total units utilized: 150
Total Electricity Charges: Rs. 1125.00
Illustration 2:
Input the total units utilized: 50
Total Electricity Charges: Rs. 375.00
Illustration 3:
Input the total units utilized: 0
Total Electricity Charges: Rs. 0.00
Explanation:
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:
- Start the program .
- Define the constant UNIT_RATE for the rate per unit consumed and TAX_RATE for the tax rate.
- Define the function calculateBill that takes the number of units consumed as an argument and returns the bill amount. Declare variables billAmount and taxAmount . Calculate the bill amount by multiplying the units consumed by UNIT_RATE . Calculate the tax amount by multiplying the bill amount by TAX_RATE . Add the tax amount to the bill amount. Return the bill amount.
- Define the main FunctionFunction. Declare variables units and totalBill . Prompt the user to input the number of units consumed. Read the input and store it in the units variable. Call the calculateBill FunctionFunction, passing the units variable as an argument, and store the returned value in totalBill . Display the bill amount by printing "Electricity Bill Amount: $totalBill" .
- End the program.
- Declare variables billAmount and taxAmount .
- Calculate the bill amount by multiplying the units consumed by UNIT_RATE .
- Calculate the tax amount by multiplying the bill amount by TAX_RATE .
- Add the tax amount to the bill amount.
- Return the bill amount.
- Declare variables units and totalBill .
- Prompt the user to input the number of units consumed.
- Read the input and store it in the units variable.
- Call the calculateBill FunctionFunction, passing the units variable as an argument, and store the returned value in totalBill .
- Display the bill amount by printing "Electricity Bill Amount: $totalBill" .
This algorithm outlines the steps taken in the program to calculate and display the electricity bill amount based on the user input.
### Bill Calculation:
To calculate the bill based on the given inputs and predefined rates, you can use the following formula:
billAmount = units * UNIT_RATE
Where:
billAmount represents the complete sum of the bill, encompassing the tax amount as well.
units represents the quantity of units utilized by the user.
UNIT_RATE refers to the predetermined cost for each unit of consumption.