Story Problems | Parallel Programming |
List of Story Problems | Anglish Statements |
Multiple Problem Anglish Plurals | Index |
When multiple formulas are needed to calculate a solution, the program can take two forms. For example, the two forms of the program shown below are equivalent. However, the one on the right is a better description of the actions required to solve the problem.
percent = ((total-portion wrong)/total)X100; portion right = total-portion wrong; percent = (portion right/total)X100;The order of the statements is important. They must be calculated in the order specified. Thus
portion right = total - portion wrong; and percent = (portion right/total)X100; percent = (portion right/total) X 100; right = total - portion wrong;are NOT equivalent. Given a table similar to the quiz problem, the sequence on the left produces
------------------------------- |total|portion|portion|percent| | |wrong |right | | ------------------------------- | 35 | 7 | 28 | | ------------------------------- and then ------------------------------- |total|portion|portion|percent| | |wrong |right | | ------------------------------- | 35 | 7 | 28 | 80 | -------------------------------However, the sequence on the right would attempt to perform the division "portion right/total" before the portion right had been calculated producing an error.