Question: In Lab 07 we wrote a program to calculate energy bill for households. We are going to rewrite that program with value returning functions. Energy

In Lab 07 we wrote a program to calculate energy bill for households. We are going to rewrite that program with value returning functions. Energy consumption is measured in kilowatt hours (kWh). The more kWh a household use in a month, the higher the energy bill. A power company charges customers $0.12 per kWh for the first 500 kWh. After the first 500 kWh, the rate is $0.15 per kWh. Write a program to calculate energy charge. You must write and use the following functions.

A main function: Call the value returning function get_kWh_used. Pass the return value to the value returning function bill_calculator as an argument. Display the return value of bill_calculator.

A get_kWh_used function: This function has no parameter. It asks the user to enter number of kWh used. Use an input validation loop to ensure that kWh used is not negative. Return kWh used.

A bill_calculator function: This function has a parameter to receive number of kWh used. Calculate and return the energy charge.

The following is an example.

Enter kilowatt hours used: -5

kWh cannot be negative.

Enter kilowatt hours used: -6

kWh cannot be negative.

Enter kilowatt hours used: 510

Please pay this amount: $61.50

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!