-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp-4-21.c
54 lines (46 loc) · 1.28 KB
/
exp-4-21.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*************************************************************************
> File Name: exp-4-21.c
> Author: xiaoxiaoh
> Mail: [email protected]
> Created Time: Mon Jul 3 12:27:08 2017
************************************************************************/
/*
* Write a C program to input electricity unit charges and calculate total electricity bill according to the given condition:
* 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
*
*/
#include <stdio.h>
int main()
{
float unit;
float amt, total_amt, sur_charge;
//read unit consumed from user
printf("Enter total units consumed: ");
scanf("%f", &unit);
/* Calculate electricity bill according to given conditions */
if(unit <= 50)
{
amt = unit * 50;
}
else if(unit <= 150)
{
amt = 50 * 0.5 + (unit - 50) * 0.75;
}
else if(unit <= 250)
{
amt = 50 * 0.5 + 100 * 0.75 + (unit - 150) * 1.20;
}
else
{
amt = 50 * 0.5 + 100 * 0.75 + 100 * 1.20 + (unit - 250) * 1.50;
}
/* Calculate total electricity bill after adding surcharge */
sur_charge = amt * 0.20;
total_amt = amt + sur_charge;
printf("Electricity bill is %.2f\n", total_amt);
return 0;
}