 # Program to input electricity unit charges and calculate total electricity bill according to the given condition-

5
(265)

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
So let’s start if you like it then share it with your friends

### Solve using C Programming

Run the Below code here

``````//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: Program to input electricity unit charges and calculate total electricity bill according to the given condition- 3

### 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:

## Electricity Bill Calculator

Number of units consumed:

Click on a star to rate it!

Average rating 5 / 5. Vote count: 265

No votes so far! Be the first to rate this post.

As you found this post useful...