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
Explanation / Answer
Basically this needs two inputs, last month's reading and the current month's reading. The output is to print the total charge for the gas used. The calculations performed are 1. The amount of the gas used, which is performed in a very traditional way i.e if last months reading is greater than the present month then gas used = 10000 - previous reading + current reading (as you mentioned) if last months reading is less than the current month's then gas used = current reading - previous reading 2. Calculation of charges let us assume four variables r1,r2,r3,r4 which are assigned to 0. let us solve this by your example the total gas used is 203 cubic meters, the cost of first 70 cubic meters is $5.0 and next 100 cubic meters is $5.0 and remaining 33 cubic meters is 82.5 cents. The below code does the same calculation in reverse order. #include #include #include using namespace std; int main() { int lmr,cmr,gu,tgu; float r1=0,r2=0,r3=0,r4,tc; cout70) { r3=(gu-70)*5.0; gu=70; } r4=500; tc=r1+r2+r3+r4; tc=tc/100; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.