166k views
4 votes
The electric company gives a discount on electricity based upon usage. The normal rate is $.60 per Kilowatt Hour (KWH). If the number of KWH is above 1,000, then the rate is $.45 per KWH. Write a program (L4_Ex1.cpp) that prompts the user for the number of Kilowatt Hours used and then calculates and prints the total electric bill. Please put comment lines, same as in Lab3, at the beginning of your program. According to your program in Lab 4.1, how much will it cost for: 900 KWH? 1,754 KWH? 10,000 KWH?

User Maghoumi
by
7.6k points

1 Answer

6 votes

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

Step-by-step 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.

User Kris Boyd
by
8.2k points