-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEBill.cpp
More file actions
64 lines (51 loc) · 1.32 KB
/
Copy pathEBill.cpp
File metadata and controls
64 lines (51 loc) · 1.32 KB
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
55
56
57
58
59
60
61
62
63
64
/* Write a 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<iostream>
using namespace std;
Ebill(double& unit)
{
cout <<"Enter the electricity units consumed"<<endl;
cin >>unit;
}
void lessThan50(double unit,double& bill) //Unit Consumed less than 50
{
bill=unit*.5;
bill+=(.2*bill);
}
void lessThan150(double unit,double& bill) //Unit Consumed less than 150
{
unit-=50;
bill=25+(unit*.75);
bill+=(.2*bill);
}
void lessThan250(double unit,double& bill) //Unit Consumed less than 250
{
unit-=150;
bill=100+(unit*1.2);
bill+=(.2*bill);
}
void moreThan250(double unit,double& bill) //Unit Consumed more than 250
{
unit-=250;
bill=220+(unit*1.5);
bill+=(.2*bill);
}
int main()
{
double unit,bill=0.0;
Ebill(unit); //Inputting units consumed
if(unit<=50)
lessThan50(unit,bill);
else if(unit<=150)
lessThan150(unit,bill);
else if(unit<=250)
lessThan250(unit,bill);
else
moreThan250(unit,bill);
cout <<"\n The total bill = Rs"<<bill;
return 1;
}