Answer:
The cpp program for the given scenario is shown below.
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
//variables to hold both the given values
double normal_rate = 0.60;
double rate_1000 = 0.45;
//variable to to hold user input
double kwh;
//variable to hold computed value
double bill;
std::cout << "Enter the number of kilowatt hours used: ";
cin>>kwh;
std::cout<<std::endl<<"===== ELECTRIC BILL ====="<< std::endl;
//bill computed and displayed to the user
if(kwh<1000)
{
bill = kwh*normal_rate;
std::cout<< "Total kilowatt hours used: "<<kwh<< std::endl;
std::cout<< "Rate for the given usage: $"<<normal_rate<< std::endl;
std::cout<< "Total bill: $" <<bill<< std::endl;
}
else
{
bill = kwh*rate_1000;
std::cout<< "Total kilowatt hours used: "<<kwh<< std::endl;
std::cout<< "Rate for the given usage: $"<<rate_1000<< std::endl;
std::cout<< "Total bill: $" <<bill<< std::endl;
}
std::cout<<std::endl<< "===== BILL FOR GIVEN VALUES ====="<< std::endl;
//computing bill for given values of kilowatt hours
double bill_900 = 900*normal_rate;
std::cout << "Total bill for 900 kilowatt hours: $"<< bill_900<< std::endl;
double bill_1754 = 1754*rate_1000;
std::cout << "Total bill for 1754 kilowatt hours: $"<< bill_1754<< std::endl;
double bill_10000 = 10000*rate_1000;
std::cout << "Total bill for 10000 kilowatt hours: $"<< bill_10000<< std::endl;
return 0;
}
OUTPUT
Enter the number of kilowatt hours used: 555
===== ELECTRIC BILL =====
Total kilowatt hours used: 555
Rate for the given usage: $0.6
Total bill: $333
===== BILL FOR GIVEN VALUES =====
Total bill for 900 kilowatt hours: $540
Total bill for 1754 kilowatt hours: $789.3
Total bill for 10000 kilowatt hours: $4500
Explanation:
1. The program takes input from the user for kilowatt hours used.
2. The bill is computed based on the user input.
3. The bill is displayed with three components, kilowatt hours used, rate and the total bill.
4. The bill for the three given values of kilowatt hours is computed and displayed.