Answer to Question #319489 in C++ for Ajay

Question #319489

Beyond 300 units Rs.5.00 per unit



An electricity board charges the following rates to domestic users to discourage large consumption



of energy.



For the first 100 units Rs 1.50 per unit



For the next 200 untis Rs 3.00 per unit



All users are charged a minimum of Rs. 100. If the total cost exceeds Rs.250, then an additional



surcharge of 15% is added. Write a program to read the name of user and number of units consumed



and print out the charges with name.

1
Expert's answer
2022-03-28T11:01:05-0400
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


int main() {
    string name;
    int consumption;
    double charge;

    cout << "Enter a name: ";
    cin >> name;
    cout << "Enter a number of consumption units: ";
    cin >> consumption;

    if (consumption <= 100) {
        charge = consumption * 1.50;
    }
    else {
        charge = 100 * 1.50;
        if (consumption <= 300) {
            charge += (consumption - 100) * 3.00;
        }
        else {
            charge += 200 * 3.00;
            charge += (consumption - 300) * 5.00;
        }
    }
    if (charge < 100) {
        charge = 100;
    }
    if (charge  > 250) {
        charge *= 1 + 15/100.0;
    }

    cout << name << ": Rs. " << fixed << setprecision(2) << charge;

    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