Answer to Question #175475 in C++ for Ben

Question #175475

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?


1
Expert's answer
2021-03-25T17:04:41-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS