女征男 (DC)# Piebridge - 鹊桥
s*0
1 楼
The manager of PG&E wants a program that calculates a customer's electric
bill. He will enter the current and previous meter readings. The program
should calculate and display the number of units of electricity used and the
total charge for the electricity. The charge for each unit of electricity
is $0.11. The program allows the user to display the electric bill for more
than one customer without having to run the program again. Use a sentinel
value to end the program.
Create 3 functions:
getInput: Gets the current and previous meter readings from the user. If
the user does not enter a sentinel value as the current reading, the
getInput function should prompt the user to enter the previous reading. To
be valid, the current reading must be greater than or equal to the previous
reading. The main function should not call the calcBill or displayBill
functions when the readings are not valid. Instead, it should display an
error message.
calcBill: Calculates both the number of units used and the total charge.
displayBill: Displays both the number of units used and the total charge.
Input Validation: Do not accept negative numbers for meter readings.
Sample run:
Current reading (negative number to end): 4000
Previous reading: 1000
Units used: 3000
Total charge: $330.00
Current reading (negative number to end): 4000
Previous reading: 5000
The current reading must be greater than or equal to the previous reading.
bill. He will enter the current and previous meter readings. The program
should calculate and display the number of units of electricity used and the
total charge for the electricity. The charge for each unit of electricity
is $0.11. The program allows the user to display the electric bill for more
than one customer without having to run the program again. Use a sentinel
value to end the program.
Create 3 functions:
getInput: Gets the current and previous meter readings from the user. If
the user does not enter a sentinel value as the current reading, the
getInput function should prompt the user to enter the previous reading. To
be valid, the current reading must be greater than or equal to the previous
reading. The main function should not call the calcBill or displayBill
functions when the readings are not valid. Instead, it should display an
error message.
calcBill: Calculates both the number of units used and the total charge.
displayBill: Displays both the number of units used and the total charge.
Input Validation: Do not accept negative numbers for meter readings.
Sample run:
Current reading (negative number to end): 4000
Previous reading: 1000
Units used: 3000
Total charge: $330.00
Current reading (negative number to end): 4000
Previous reading: 5000
The current reading must be greater than or equal to the previous reading.