Untitled

Oct 26th, 2020
1,746
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. // Function that takes 2 arguments and returns their sum
2. float add(float a, float b, float c)
3. {
4.   return a + b + c;
5. }
6.
7. // 1 1 1 -> true
8. // 1 1 2 -> false
9. // 1,2,4 -> false
10. // 2,2,2 -> true
11. // 2,3,2 -> false
12. // x y z -> x == y && y == z
13. // compare3Numbers(int, int, int) = boolean
14. boolean compare3Numbers(int x, int y, int z)
15. {
16.   if(x == y && y == z)
17.     return true;
18.   else
19.     return false;
20. }
21.
22. // squareConditionally(a, p) -> a^2 if p is true, else a
23. // squareConditionally(4,true) -> 16
24. // squareConditionally(4,false) -> 4
25. // squareConditionally(5,false) -> 5
26. // squareConditionally(5,true) -> 25
27. // squareConditionally(int, boolean) = int
28. int squareConditionally(int a, boolean p)
29. {
30.   if(p == true)
31.     return (int)pow(a, 2);
32.   else
33.     return (int)a;
34. }
35.
36. void setup()
37. {
38.   float x = add(1, 3, 4); // add(float, float, float) = float
39.   boolean p = compare3Numbers(-5, -5, -5);
40.
41.   int sqr = squareConditionally(4, false);
42.
43.   print(sqr);
44. }
45.
46. void draw()
47. {
48.
49. }
RAW Paste Data