Answer to Question #151949 in C++ for Nadia zafar

Question #151949
Write a Program to find the electricity Bill of a consumer so that the Bill for first 50 units is Rs 3/unit, for next 50 units is Rs. 5/Unit, for next 100 units is Rs. 7/Unit, for next 100 units is Rs. 15/unit and for upcoming units is Rs. 25/unit.

For Example.

If a consumer consumes 200 units, then the Bill will be:

50*3 = 150

50*5 = 250

100*7 = 700

Total Bill = Rs. 1100
1
Expert's answer
2020-12-18T09:23:39-0500
#include <iostream>
using namespace std;
int main()
{
    int unit;
    int total_bill;
    /* Input unit consumed from user */
    cout << "Enter total units consumed: ";
    cin >> unit;
    /* Calculate electricity bill according to given conditions */
    if(unit <= 50) {
        total_bill = unit * 3;
    }
    else if(unit <= 100) {
        total_bill = 50 * 3 + ((unit-50) * 5);
    }
    else if(unit <= 200) {
        total_bill = 50 * 3 + 50 * 5 + ((unit-100) * 7);
    }
    else if (unit <= 300) {
        total_bill = 50 * 3 + 50 * 5 + 100 * 7 + ((unit-200) * 15);
    }
    else {
      total_bill = 50 * 3 + 50 * 5 + 100 * 7 + 100 * 15 + ((unit - 300) * 25);
    }
    
    cout << "Electrcity Bill: " << total_bill;
    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