// An electricity provider charges the // following rates for monthly consumption: // // Consumption Rate // First 100 kWh $0.10/kWh // Next 200 kWh $0.15/kWh // Above 300 kWh $0.20/kWh // // Given a nonnegative integer consumption, // calculate and print the total bill. // Each rate applies only to the electricity // consumed within its corresponding tier. // // For example, a household consuming // 340 kWh pays for // 100 kWh at $0.10, so 10.00 // 200 kWh at $0.15, so 30.00 // 40 kWh at $0.20, so 8.00 // for a total of $48.00 // // Display "Invalid consumption." if the // number is negative and return -1. // // Instead of using floating-point numbers, // use integers and calculate the number of // cents that must be paid. To display the // amount owed: // 1. Print the string "$". // 2. Print the total divided by 100. // 3. Print a ".". // 4. Determine the remainder modulo 100: // a. If the remainder is 0, print "00". // b. If the remainder is less than ten, // print a "0" and the remainder. // c. Otherwise, print the remainder. // All values will be integers, including the // number of kilowatt-hours and the prices // in cents. This avoids round-off errors. // // Note: a watt is a joule per second, and // an hour is 3600 seconds. Thus a // kilowatt-hour or kWh is // 1000 J/s x 3600 s = 3 600 000 J, // or // 3.6 MJ. // // Why do we not just charge per MJ? Electrical // energy has traditionally been measured in // kilowatt-hours because this unit relates // energy consumption directly to electrical // power and time. For example, if you leave // a 100 W light bulb running for one hour, // it consumes 0.1 kWh. // Function declarations int main(); // Function definitions int main() { // Query the user for a nonnegative integer // number of kilowatt-hours and assign it to // 'consumption'. return 0; }