Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function that takes 2 arguments and returns their sum
- float add(float a, float b, float c)
- {
- return a + b + c;
- }
- // 1 1 1 -> true
- // 1 1 2 -> false
- // 1,2,4 -> false
- // 2,2,2 -> true
- // 2,3,2 -> false
- // x y z -> x == y && y == z
- // compare3Numbers(int, int, int) = boolean
- boolean compare3Numbers(int x, int y, int z)
- {
- if(x == y && y == z)
- return true;
- else
- return false;
- }
- // squareConditionally(a, p) -> a^2 if p is true, else a
- // squareConditionally(4,true) -> 16
- // squareConditionally(4,false) -> 4
- // squareConditionally(5,false) -> 5
- // squareConditionally(5,true) -> 25
- // squareConditionally(int, boolean) = int
- int squareConditionally(int a, boolean p)
- {
- if(p == true)
- return (int)pow(a, 2);
- else
- return (int)a;
- }
- void setup()
- {
- float x = add(1, 3, 4); // add(float, float, float) = float
- boolean p = compare3Numbers(-5, -5, -5);
- int sqr = squareConditionally(4, false);
- print(sqr);
- }
- void draw()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement