Code Logo

Calculate Phone Bill

Published at19 Apr 2026
Calculations & Math Easy 6 views
Like0

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.

Learn about our pseudocode specification
Guide

Example Input & Output

Example 1
Input
base_fee = 10, extra_minutes = 4, cost_per_minute = 1
Output
14
Explanation

The extra cost is 4, so the total becomes 14.

Example 2
Input
base_fee = 15, extra_minutes = 0, cost_per_minute = 3
Output
15
Explanation

With no extra minutes, the final bill stays the same as the base fee.

Example 3
Input
base_fee = 20, extra_minutes = 5, cost_per_minute = 2
Output
30
Explanation

The extra 5 minutes cost 10, so the final bill becomes 30.

Algorithm Flow

Recommendation Algorithm Flow for Calculate Phone Bill
Recommendation Algorithm Flow for Calculate Phone Bill

Solution Approach

Apply the base fee and add overage charges for minutes beyond the allocation.

function phoneBill(minutes)
  if minutes == 0 then return 0
  bill = 10
  if minutes > 100 then
    bill = bill + (minutes - 100) * 0.05
  return bill

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

Pseudocode - Approach 1
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)
endprogram