an electricity board charges according to following rates for the first 100 units-rs 4 per unit , for the next 200 units-Rs5 per unit,beyond 300 units-Rs 6 per unit.All users charged Meter charge also ,which is Essentially 70.write a program in C++ to read the number of units consumed and print out the charges
Answers
Following program calculates the electricity charges with 70 fixed + first 100 units at Rs.4, next 200 at Rs.5 and @ Rs.6 after wards.
#include <iostream>
using namespace std;
int main()
{
int units; //Input the units consumed
int charges; // Total charge.
int chargeperunit;
// Input the units consumed.
cin >> units;
units = 400;
charges = 70; //fixed charges for the meter.
chargeperunit = 4; //Rs 4 for first 100 units
if (units)
{
if (units <= 100)
{
charges = charges + units * chargeperunit;
units = 0;
}
else
{
charges = charges + 100*chargeperunit;
units = units - 100;
}
chargeperunit = chargeperunit + 1; // Increase charge for next level.
}
// Charges for next level of units @ Rs. 5 per unit.
if (units)
{
if (units <= 200)
{
charges = charges + units * chargeperunit;
units = 0;
}
else
{
charges = charges + 200 * chargeperunit;
units = units - 200;
}
chargeperunit = chargeperunit + 1; // Increase charge for next level.
}
// Remaining are charges at Rs.6 per unit
charges = charges + units * chargeperunit;
cout << "Total Electricity charge is " << charges << endl;
return 0;
}