**Problem Link**:[https://www.codechef.com/problems/EXOCODE7/][1]

**Author**[:https://www.codechef.com/users/vivek96][2]

**DIFFICULTY**:Cakewalk

**PREREQUISITES**:basic programming,basic maths

**PROBLEM**:Chef wants to calculate his Electricity bill,Help him to do so

Acc to Conditions:-

For First 50 units Rs 0.50/unit

For next 100 units Rs 0.75/unit

For next 100 units Rs 1.20/unit

For unit above 250 Rs 1.50/unit

An additional surcharge of 20% is added to the bill

**EXPLANATION**:

Below is the step by step descriptive logic to compute electricity bill.

1-Read units consumed by the customer in some variable say unit.

2-If user consumed less or equal to 50 units. Then amt = unit * 0.50.

3-If user consumed more than 50 units but less than 100 units. Then add the first 50 units amount i.e. 25 to the final amount and compute the rest 50 units amount. Which is given by amt = 25 + (unit-50) * 0.75. I have used units-50, since I already calculated first 50 units which is 25.

4-Likewise check rest of the conditions and calculate total amount.

5-After calculating total amount. Calculate the surcharge amount i.e. sur_charge = total_amt * 0.20. Add the surcharge amount to net amount. Which is given by net_amt = total_amt + sur_charge.

**AUTHOR’S AND TESTER’S SOLUTIONS**:

int main()

{

int unit;

```
float amt, total_amt, sur_charge;
/*
* Read unit consumed from user
*/
printf("Enter total units consumed: ");
scanf("%d", &unit);
/*
* Calculate electricity bill according to given conditions
*/
if(unit less then equal to 50)
{
amt = unit * 0.50;
}
else if(unit less then equal to 150)
{
amt = 25 + ((unit-50)*0.75);
}
else if(unit less then equal to 250)
{
amt = 100 + ((unit-150)*1.20);
}
else
{
amt = 220 + ((unit-250)*1.50);
}
/*
* Calculate total electricity bill
* after adding surcharge
*/
sur_charge = amt * 0.20;
total_amt = amt + sur_charge;
printf("%.2f", total_amt);
return 0;
```

}

Note–>printf("%.2f) is use for controlling precission

[1]: https://www.codechef.com/problems/EXOCODE7/

[2]: https://www.codechef.com/users/vivek96