Today we will create a program in which Program to input electricity unit charges and calculate total electricity bill according to the given condition-
For first 50 units Rs. 0.50/units
For next 100 units Rs. 0.75/units
For next 100 units Rs. 1.20/units
For units above 250 Rs. 1.50/units
and an additional surcharge of 20% is added to the bill.
So let’s start if you like it then share it with your friends
Table Of Contents
Solve Using Python
Solve using C Programming
//Code by RakeshMgs
#include <stdio.h>
int main()
{
int units;
float bill;
// Get the number of units consumed
printf("Enter the number of units consumed: ");
scanf("%d", &units);
// Calculate bill for first 50 units
if (units > 0 && units <= 50) {
bill = units * 0.50;
}
// Calculate bill for next 100 units
else if (units > 50 && units <= 150) {
bill = (50 * 0.50) + ((units - 50) * 0.75);
}
// Calculate bill for next 100 units
else if (units > 150 && units <= 250) {
bill = (50 * 0.50) + (100 * 0.75) + ((units - 150) * 1.20);
}
// Calculate bill for units above 250
else if (units > 250) {
bill = (50 * 0.50) + (100 * 0.75) + (100 * 1.20) + ((units - 250) * 1.50);
}
// Add surcharge to the bill
bill += bill * 0.20;
// Print the bill
printf("Total electricity bill: Rs. %.2f", bill);
return 0;
}
Output:

Solve Using JavaScript
<!--Code By RakeshMgs-->
<!DOCTYPE html>
<html>
<body>
<h2>Electricity Bill Calculator</h2>
<form>
Number of units consumed: <input type="text" id="units" name="units"><br><br>
<input type="button" value="Calculate Bill" onclick="calculateBill()">
</form>
<p id="bill"></p>
<script>
function calculateBill() {
let units = document.getElementById("units").value;
let bill;
if (units > 0 && units <= 50) {
bill = units * 0.50;
} else if (units > 50 && units <= 150) {
bill = (50 * 0.50) + ((units - 50) * 0.75);
} else if (units > 150 && units <= 250) {
bill = (50 * 0.50) + (100 * 0.75) + ((units - 150) * 1.20);
} else if (units > 250) {
bill = (50 * 0.50) + (100 * 0.75) + (100 * 1.20) + ((units - 250) * 1.50);
}
bill += bill * 0.20;
document.getElementById("bill").innerHTML = "Total electricity bill: Rs." + bill;
}
</script>
</body>
</html>
Output: