IPA IP 2025 Question 99
A question IPA Japan published in 令和7年度 ITパスポート試験 公開問題 問99, translated into English. ITPEC is based on the same exams.
The function calculateAmountOfPrize receives the improvement amount and the reduction period in the effects of a business improvement as improvement and period respectively, and returns the prize amount as the return value. There were a business improvement with an improvement amount of 200,000 yen and a reduction period of 3 days, and a business improvement with an improvement amount of 50,000 yen and a reduction period of 14 days. How many yen is the total of these two prize amounts? Here, the values of the improvement amount and the reduction period are each 0 or more.
Explanation
3,000 yen — trace each improvement through the two nested if statements and add the prizes.
The outer if splits on the improvement amount (below 100,000 yen or not), the inner one on the reduction period (below 7 days or not):
- •200,000 yen, 3 days:
improvementis not less than 100000, so theelsebranch;period3 is less than 7, soprize← 2000 - •50,000 yen, 14 days:
improvementis less than 100000;period14 is not less than 7, soprize← 1000
Total: 2,000 + 1,000 = 3,000 yen. Running the function on both inputs gives the same.
Answer (c)
Why not others:
- •(a) 1,000 — counts only the second improvement's prize
- •(b) 1,500 — gives the 200,000-yen improvement 500, as if it were below 100,000 yen
- •(d) 5,500 — gives the 200,000-yen improvement 5000 and the other 500, swapping the two
periodtests
Key rule: With nested conditions, settle the outer test first, then the inner one inside that branch only, and check each boundary (“less than” excludes the value itself).
Algorithm and Programming · AI-written, may contain errors
This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.