COMPUTE identifier-1 [ROUNDED] = arithmetic expression.The answer that results from the calculation is stored in identifier-1 which is usually defined in WORKING-STORAGE.
Math........................................ | COBOL............................................................................ |
---|---|
x=a(b+c)/d | COMPUTE X = A * (B + C) / D. The actual multiply sign (*) must be shown. |
x = a + b(c-5)+d(e-6) | COMPUTE X = A + B * (C - 5) + D * (E - 6). The subtracts will be done because they are in ( ) and then the multiplies left to right followed by the adds left to right. |
x = a+b/c+d | COMPUTE X = A + B / C + D. B will divided by C first and then A and D will be added |
x=(a+b)/(c+d) | COMPUTE X = (A + B) / (C + D). Addition will be done first because it is in ( ) and then divide. |
x=a(b+c((d+e)/(f+g)+h)) | COMPUTE X = A * (B + C * ((D + E) / (F + G) + H)). D and E are added and F and G are added and the divide is done, then H is added in and the whole thing is multiplied by C, then that answer is added to B and everything is multiplied by A |
x=(a+b)(d+(e-f)/(g-30)) | COMPUTE X = (A + B) * (D + (E - F) / (G - 30)). E-F will be divided by G-30 and the answer will be added to D. A will be added to B and then the multiply will take place. |