A Telephone Bill in Slabs

Medium

Read the customer's name as a whole line, which may contain spaces, then the number of units used as an integer on the next line, and print the bill. The first 100 units cost 95 paise each, the next 75 units cost Rs 1.50 each, and every unit beyond 175 costs Rs 2.85. Every customer pays a service charge of Rs 75. If the total amount, call charge plus service charge, is more than Rs 500, add a surcharge of 12.5% of that total. Print six lines in exactly this form: name: Asha Rao, units consumed: 200, call charge: 278.75, service charge: 75.00, surcharge: 0.00, total amount: 353.75, with every amount to two decimal places. Read the name with fgets and remove the trailing newline. If the units are negative print units cannot be negative and return 1. If the name or the units cannot be read print invalid input and return 1.

Success Criteria

Your code must pass 6 test case(s) to complete this exercise. 3 hint(s) are available if you need help.

How did you find this exercise?

Your rating helps us improve the content.

Sign in to track your progress

You can work on exercises as a guest, but sign in to track your progress and save your submissions.

This platform is built by its community

Every lesson, project, and tool on HelloC++ is funded by sponsors. Join them and help shape what we build next.

Become a Patron