For this problem, add a Divide action with two number parameters and a number return value for this problem. In addition, you will need to do some error checking to check if the divisor is zero. If it is zero, output a message Error, cannot divide by zero. and return 0.0. Otherwise, return the division result.
Once you have completed the action, call the action with the arguments 34.0 and 2.0(e.g., otherResult = Divide(34.0, 2.0)). Then, output the results. Call the action a second time with arguments 34.0, 0.0 and output the result. When run, the program should output the following.
-6 -2 15 17.0 Error, cannot divide by zero. 0.0.
Coding:
Hotkey Shortcuts
Move BlocksUP or DOWN or TAB
Run Program ALT + SHIFT + R
Stop Program ALT + SHIFT + S
Hide Tray ALT + SHIFT + X
Zoom In ALT + +
Zoom Out ALT + -
Open Help ALT + SHIFT + H
Navigate to Tray ALT + 1
Navigate to Blocks ALT + 2
Enter Navigation Mode SHIFT + ENTER
Switch to Next Tab CTRL + Tab
Switch to Previous TabCTRL + Shift + Tab
Blocks
Hint
Great job!
Try again
Using the other three actions as a guide, build the Divide action, action Divide(number a, number b) returns number. Use an if block to check if the divisor is 0 and output an error message with a return value of 0.0 if it is. Otherwise, divide and return the result.