In order to discourage excess consumption, an electric company charges its customers a lower rate, namely $0.11, for each of the first 250 kilowatt hours, and higher rate of $0.17 for each additional kilowatt hour. In addition, 10% surtax is added to the final bill. Write a program to calculate electric bills given the number of kilowatt hours consumed as input. Use two function declarations: one to compute the amount due without the surtax and one to compute the total due with surtax.
#include <iostream>
using namespace std;
double ElectricityBillWithoutSurtax(double kilowattHoursConsumed)
{
return (kilowattHoursConsumed <= 250.0) ? kilowattHoursConsumed * 0.11 : 250.0 * 0.11 + (kilowattHoursConsumed - 250.0) * 0.17;
}
double ElectricityBillWithSurtax(double kilowattHoursConsumed)
{
return ElectricityBillWithoutSurtax(kilowattHoursConsumed) * 1.1;
}
int main()
{
double kh;
cout << "Enter the number of kilowatt hours of electricity that the client has spent.\n";
cin >> kh;
cout << "The amount due without the surtax : $" << ElectricityBillWithoutSurtax(kh) << endl;
cout << "The total due with surtax : $" << ElectricityBillWithSurtax(kh) << endl;
}
Comments
Leave a comment