Question #45495
an electricity board charges the following rates to domestic users:-
for the first 100 units-40p/unit
for the next 200 units-50p/unit
beyond 300 units-60p/unit
write a program to read the names of users and number of units consumed and print out the charges with names.
1
Expert's answer
2014-09-02T05:54:40-0400
#include <iostream>#include <string>int main() {    const int first100 = 40;    const int next200 = 50;    const int beyond300 = 60;    std::string name;    int unitsConsumed, payment = 0;    std::cout << "Please enter your name" << std::endl;    std::cin >> name;    std::cout << "Please enter units consumed" << std::endl;    std::cin >> unitsConsumed;    if ( unitsConsumed <= 100 && unitsConsumed > 0 ) {        payment = first100 * unitsConsumed;    } else if (unitsConsumed > 100 && unitsConsumed <= 300 ) {        payment = next200 * unitsConsumed;    } else if (unitsConsumed > 300 ) {        payment = beyond300 * unitsConsumed;    } else {        std::cout << "Ammount can not be negative. Ending program..." << std::endl;        return 0;    }    std::cout << "Dear " << name << ",\nYou have consumed " << unitsConsumed << " units, which requires " << payment << " credits." << std::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!
LATEST TUTORIALS
APPROVED BY CLIENTS