Answer to Question #319467 in C++ for Ajay

Question #319467

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

1
Expert's answer
2022-03-28T08:03:39-0400
#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;
}

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