My program is not working as it should.Help me.

I am trying to create a electric bill calculating program which calculates based from the rate given below

The rate:
First 20 kWh = 25 cent / kWh
o Next 20 kWh = 37 cent / kWh
o Next 10 kWh = 43 cent / kWh
o More than 50 kWh = 51 cent / kWh

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
  #include<iostream>
using namespace std;
void main()
{

cout<<"\n\n\n\tElectricity Board Charges\n";

cout<<"\n\nEnter Number of Units Consumed:";
float unit;
cin>>unit;

//MANIPULATION
float tc;
if(unit=20)
tc=unit*0.29f;
else if(unit>20)
tc=unit*0.38f;
else if(unit>=10 && unit<=50 )
tc=unit*0.47f;
else
tc=unit*0.54f;




float total_cost;
total_cost =tc;

cout<<"\n\nYOUR BILL AMOUNT IS "<< total_cost;


}
2 problems:
void main()

should be

int main()

and

if(unit=20)

should be

if(unit==20)
Line 14: You're using the assignment operator, not a comparison operator.

Your if statements are wrong.
Lines 14-15: This calculation is applied unconditionally, but only for the first 20kwh.
Lines 16-17: This calculation is for kwh>20 and <40 and excludes the first 20kwh.
Lines 18-19: This calculation is for kwh >40 and <50 and excludes the first 40kwh.

Lines 15,17,19,21: Your amounts are wrong.


Topic archived. No new replies allowed.