This is a “gas meter” problem. The gas meters in the problem show integer values
ID: 3639535 • Letter: T
Question
This is a “gas meter” problem. The gas meters in the problem show integer values only in the range of 0 to 9999 cubic meters. When the meter reaches 9999, it then “starts over” with the value 0000. This is a common consideration that has to be handled anytime we measure things, since all measurement devices place a limit on the largest number the device can record.
Problem statement
Suppose charges by a gas company are based on the user’s consumption, according to the following table:
Gas Used Rate
First 70 cubic meters $5.00 minimum cost
Next 100 cubic meters 5.0 cents per cubic meter
Next 230 cubic meters 2.5 cents per cubic meter
Above 400 cubic meters 1.5 cents per cubic meter
Ensure that you charge only once at the correct rate for each cubic meter of gas.
Write a program that computes the charges for a given amount of gas usage. Have the program read in the meter reading for the previous month and the reading for the current month, each an integer with up to 4 digits, and each reading representing cubic meters. The program should then calculate and display the amount of payment due from the customer. NOTE: The reading for the current month could be less than the reading for the previous month, because after the reading reaches 9999, it starts over with the value 0000. For example, if the previous month’s reading was 9875 and the current month’s reading was 0078, the customer actually used 203 cubic meters during the current month. This can probably be calculated in a variety of ways. A straightforward way, of course, is to subtract 9875 from 10000 and add 78 to the result. This approach will be satisfactory for our purposes, when the current reading is less than the previous reading, i.e., in that case uses the following formula:
Gas used = 10000 - previous reading + current reading
If the current reading is greater than the previous reading, then of course we just have to subtract the previous reading from the current reading.
Display your result in the way illustrated by the following example:
Last Month’s Reading: 9875 cubic meters
This Month’s reading: 0078 cubic meters
Gas Used: 203 cubic meters
Total Charges: $10.83