+ 1

How I can solve this

You are making a car parking software that needs to calculate and output the amount due based on the number of hours the car was parked. The fee is calculated based on the following price structure: - the first 5 hours are billed at $1 per hour. - after that, each hour is billed at $0.5 per hour. - for each 24 hours, there is a flat fee of $15. This means, that, for example, if a car parked for 26 hours, the bill should be 15+(2*0.5) = 16.0, because it was parked for 24 hours plus 2 additional hours.

7th Jan 2023, 10:33 AM
Abdelmgeid Elshanawany
Abdelmgeid Elshanawany - avatar
3 Answers
+ 1
The total cost will have 3 components as explained. You can store each of them in a separate variable and add them at the end. First you should calculate the number of full days. You can just divide the number of hours by 24. If you use Int data type for every variable, this will get you exactly the number of full days rounded down. Multiply by 15 for this cost part. Then calculate how many hours remain. If it's less than 5, multiply this by 1 (so the cost is the same as the number of hours). If more than 5 hours remain, then this part is 5 and you should also calculate the third part at the rate of 0.5 If you post your code attempt, you may get more specific directions.
7th Jan 2023, 6:33 PM
Tibor Santa
Tibor Santa - avatar
0
https://code.sololearn.com/cGxGvUu7Ue8u/?ref=app Something like that, a little example, it's very easy, look at..
7th Jan 2023, 8:17 PM
Smith Welder
Smith Welder - avatar
0
Thanks šŸ™
8th Jan 2023, 1:34 AM
Abdelmgeid Elshanawany
Abdelmgeid Elshanawany - avatar