# Cascaded function call question

**URL:** <https://discourse.processing.org/t/cascaded-function-call-question/15688>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [November 21, 2019, 12:34pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688 "2019-11-21T12:34:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)\
**Post date:** [November 21, 2019, 12:34pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/1 "2019-11-21T12:34:23Z")

</div>

```auto
int chi(int a) { 
   int b = foo(a);
   if(b < 5 ) {
      return a - b;
   }
   else {
      return a - b + 10;
   }  
} 

```

- 47
- 283
- 0  
how to do this question?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 21, 2019, 12:42pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/2 "2019-11-21T12:42:24Z")

</div>

Is this homework?

Can you post the entire task?

It is not understandable

---

<div class="post-metadata">

**Author:** ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)\
**Post date:** [November 21, 2019, 12:43pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/3 "2019-11-21T12:43:16Z")

</div>

its a question in class question thats the question

---

<div class="post-metadata">

**Author:** ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)\
**Post date:** [November 21, 2019, 12:43pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/4 "2019-11-21T12:43:51Z")

</div>

What is the value returned by each of the following functions if the value of the parameter passed is:

1. 47
2. 283
3. 0

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 21, 2019, 12:45pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/5 "2019-11-21T12:45:03Z")

</div>

Thank you for your answer

println(chi(47)); in setup()

Chrisir

---

<div class="post-metadata">

**Author:** ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)\
**Post date:** [November 21, 2019, 12:51pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/6 "2019-11-21T12:51:32Z")

</div>

The returned value would depends on what the function `foo()` does I’d say. Are you certain this is everything?

---

<div class="post-metadata">

**Author:** ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)\
**Post date:** [November 21, 2019, 1:07pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/7 "2019-11-21T13:07:14Z")

</div>

yea very thats all i have

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6c55dd4ce953cbe11a5e0e039cb7da6381d40ac3.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 21, 2019, 1:25pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/8 "2019-11-21T13:25:54Z")

</div>

Excellent

You need setup and my println() line above within setup

Then test all 3 values with all 3 functions

---

<div class="post-metadata">

**Author:** ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)\
**Post date:** [November 21, 2019, 1:29pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/9 "2019-11-21T13:29:14Z")

</div>

this is a practice for my final exam i am not going to be able to have processing program i need to do it on pen and paper

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 21, 2019, 3:49pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/10 "2019-11-21T15:49:58Z")

</div>

ah, ok.

You could make a table

```auto
                      2.1 | 2.2 | 2.3
    47 |
    283 |
    0 |

```

and fill this.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [November 24, 2019, 6:20pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/11 "2019-11-24T18:20:02Z")

</div>

> [@meow](#):
>
> how to do this question?

Start by looking at what `foo()` does, as @Tiemen suggested. It was defined previously: the code from question 2.3 calls the code from question 2.1…

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 24, 2019, 6:40pm UTC](https://discourse.processing.org/t/cascaded-function-call-question/15688/12 "2019-11-24T18:40:46Z")

</div>

I‘m not quite sure where you have a problem… if you have to do it on pen and paper, just replace the variable name a with the variable you are testing for.

So for 2.3 it would just look like this :

```auto
int chi (47) {
   int b = foo(47) = 47%10 = 7
   if (7 < 5) {
      return 47 - 7 = 40;
   } else {
      return 47 - 7 + 10 = 50; // this one will be returned
   }
}

```

I have to say, this i very Basic Math (3rd elementary at most) and the most basic principle of programming (knowing that variables have values and that functions are evaluated right when they are called before going on to the next line and knowing how return works)…
