Working on the 'if' conditions

The problem to solve that requires a couple ‘if/else’ statements.

1
2
3
4
5
6
An electric company measures the amount of electricity its customer use in kilowatt hours (kwh) and charges them
according to the following schedule:
first 12 kwh or less $2.80
next 78 kwh 8 cents each kwh
excess above 90 kwh 6 cents each kwh
Note that the minimum bill is $2.80. Write a program to calculate a customers bill

This is first draft on how it should be worked out pseudo like.

1
2
3
4
5
6
FlatFee 12kwh < $2.80 //will always be charged this.
the NEXT 78kwh (12kwh+78kwh) = 90kwh 0.08 // the wording is to show that its less than 90
>90kwh 0.06 //the rest of the bill.
//if the used was 91kwh... this is the sum.
>> 91kwh = 2.80 + (1x0.08) + (1x0.06)
FlatFee + one instance of the <90 + one instances of the >90.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int usage = 0;
usage = int.Parse(txtboxUsage.Text);
double cost = 0.0;
double flat = 2.8;


if (usage <= 12)
{
cost = flat;
//cost = (usage * 0.8) + 2.8;
}
else if (usage > 12 && usage <= 90)
{
cost = (usage - 12) * 0.08 - (cost - flat);
}
else if (usage > 90)
{
cost = flat + 78 * 0.08 + (usage - 90) * 0.06; //hmmm need to work this one out.
}

cost = double.Parse(cost.ToString());
txtboxBill.Text = cost.ToString();