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.
#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;
}
Comments
Leave a comment