The monthly electricity charges (in cent) in the United State are calculated as follows;
First 50 units at 98
Next 100 units at 22 per 10 units
Next 150 units at 35 per 10 units
Next 300 units at 45 per 10 units
Remaining units at 60 per 10 units
a) If New York used 945 units in a month, how much will he pay?
b) Chicago paid 23.88 dollars for electricity he consumed in one month. How many units of electricity did he consumed?
#include <iostream>
using namespace std;
int main () {
int unit;
float charge = 0;
cout << "Enter a unit: "; cin >> unit;
if (unit > 50) {
if (unit > 150) {
if (unit > 300) {
if (unit > 600) {
charge = charge + 98 + 220 + 525 + 1350 + (unit - 600) * 60 / 10.0;
} else {
charge = charge + 98 + 220 + 525 + (unit - 300) * 45 / 10.0;
}
} else {
charge = charge + 98 + 220 + (unit - 150) * 35 / 10.0;
}
} else {
charge = charge + 98 + (unit - 50) * 22 / 10.0;
}
} else {
charge = 98;
}
cout << "charge = " << charge << endl;
return 0;
}
Comments
Leave a comment