Calculate Phone Bill
Given the number of minutes used on a phone plan, calculate the total bill. The plan charges a base fee of 10 for the first 100 minutes. Each minute beyond 100 costs 0.05 per minute. If the minutes used are 0, the bill is 0.
For example, 50 minutes costs 10 (base). 100 minutes costs 10. 150 minutes costs 10 + 50 * 0.05 = 12.50. 200 minutes costs 10 + 100 * 0.05 = 15.00.
This problem teaches piecewise billing logic with a base allocation and overage charges. This is the same pattern used by mobile carriers, cloud service providers, and utility companies.
The solution applies the base fee if minutes exceed 0, then adds overage charges for minutes beyond 100. The result may be a floating-point number.
Edge cases include 0 minutes (return 0), exactly 100 minutes (only base fee), and very high usage where overage dominates the bill.
Example Input & Output
The extra cost is 4, so the total becomes 14.
With no extra minutes, the final bill stays the same as the base fee.
The extra 5 minutes cost 10, so the final bill becomes 30.
Algorithm Flow

Solution Approach
Apply the base fee and add overage charges for minutes beyond the allocation.
Return 0 for zero usage. Otherwise, set the base bill to 10. If minutes exceed the 100-minute allocation, calculate overage: extra minutes (minutes - 100) multiplied by the per-minute rate of 0.05, added to the base bill.
Time complexity is O(1), space complexity is O(1).
Best Answers
program calculate_phone_bill
dictionary
base_fee, extra_minutes, cost_per_minute, extra_cost, final_bill: integer
algorithm
input(base_fee, extra_minutes, cost_per_minute)
extra_cost <- extra_minutes * cost_per_minute
final_bill <- base_fee + extra_cost
output(final_bill)
endprogramComments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
