Exercise 3: Rewriting COMPUTE WS-TOTAL Using Only ADD and MULTIPLY — Possible Solution ==================================================================== The original statement is: COMPUTE WS-TOTAL = (WS-PRICE * WS-QTY) + WS-SHIPPING. REWRITING WITH DEDICATED VERBS Using only the real ADD and MULTIPLY verbs from this chapter's own material, the same calculation needs two separate steps, since neither verb alone can both multiply and add in one statement: MULTIPLY WS-PRICE BY WS-QTY GIVING WS-TOTAL. ADD WS-SHIPPING TO WS-TOTAL. The first line computes WS-PRICE times WS-QTY and stores the result directly in WS-TOTAL, using the GIVING form so WS-PRICE and WS-QTY themselves stay unchanged. The second line then adds WS-SHIPPING onto that same WS-TOTAL value, updating it in place to the final combined result. WHY THE COMPUTE VERSION IS GENUINELY EASIER TO READ HERE This chapter describes COMPUTE as accepting a real arithmetic expression directly, using standard operator precedence and parentheses exactly as in ordinary mathematical notation. The original COMPUTE statement reads almost exactly like the underlying formula itself - "total equals price times quantity, plus shipping" - in one single line, with the parentheses making the intended grouping visually obvious at a glance. The two-verb rewrite, by contrast, requires the reader to track an intermediate state: WS-TOTAL temporarily holds only the price-times- quantity subtotal after the first line, and only becomes the true final total after the second line executes. Understanding the two-verb version requires mentally simulating both steps in sequence, while the COMPUTE version expresses the entire relationship in one self-contained expression that doesn't depend on tracking an intermediate value. WHY THIS MATCHES THIS CHAPTER'S OWN GENERAL GUIDANCE This chapter's own comparison table names COMPUTE as the better choice specifically for any multi-step expression, while noting the dedicated verbs remain best for a single, simple operation. This exercise's own calculation - two operations combined, multiplication then addition - is exactly the kind of case that table already identifies as COMPUTE's own genuine strength. ANSWER: The same calculation using only dedicated verbs requires two lines: MULTIPLY WS-PRICE BY WS-QTY GIVING WS-TOTAL. followed by ADD WS-SHIPPING TO WS-TOTAL. The COMPUTE version is genuinely easier to read because it expresses the entire relationship in one line using real mathematical notation and precedence, directly mirroring the underlying formula, while the two-verb version requires tracking an intermediate subtotal state across two separate steps - exactly the kind of multi-step case this chapter's own comparison table identifies as COMPUTE's real strength over the dedicated arithmetic verbs. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly translates the COMPUTE expression into the equivalent two-step ADD/MULTIPLY sequence using the chapter's own real verb syntax, and explains the specific readability difference (one self-contained expression vs. tracking intermediate state) rather than just asserting COMPUTE is "simpler."