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 units Rs 3.00 per unit
#include <iostream>
using namespace std;
int main()
{
double rate1 = 1.5;
double rate2 = 3.0;
double rate1Units = 100.0;
double rate2Units = 200.0;
double consumptionOfEnergy;
double costOfElectricity;
cout << "Enter amount of energy consumed: ";
cin >> consumptionOfEnergy;
if (consumptionOfEnergy > rate1Units)
{
if (consumptionOfEnergy > rate1Units + rate2Units)
{
cout << "The amount of electricity consumed exceeded the tariff";
}
else
{
costOfElectricity = rate1Units * rate1 + (consumptionOfEnergy - rate1Units) * rate2;
cout << "The cost of electricity is " << costOfElectricity;
}
}
else
{
costOfElectricity = consumptionOfEnergy * rate1;
cout << "The cost of electricity is " << costOfElectricity;
}
return 0;
}
Comments
Leave a comment