How to fail successfully!

September 16, 2025

How to fail successfully? The answer is just keep going!

Failing... I've done that a lot. Specifically for this weeks problems, I feel like I don't understand a thing. I was fine at first, but I guess the three week mark is where it gets serious. I did get that tutor and we talked and introduced ourselves. But I need to give him time to review the material, which means I'm on my own this week 😭

The amount of time I've analyzed and scanned this piece of code is almost stupid. And I haven't even begun to look at other examples yet. I need a broader understanding but I feel stuck on the damn strawberry() 😂 I'm going insane.

My biggest failure so far has been coming out of lectures not understanding a thing. I haven't panicked yet though. I'm sure I can pick myself up from here with some extra time studying.

Let me share what we learned! We learned about functions, which are building blocks of a program. They put logic into modules and are reusable. You can call them and they can return a value back to you. They're organized and increase readability.

Parts of a function:

return_type function_name(parameters) {

      return value;
}

return_type:

  • what kind of value is returned examples:
  • int
  • float
  • void

function_name:

  • name you give the function

(parameters):

  • input values the function needs to work
  • each parameter has a type (int,float,etc.) and a name (like a,b)

return value:

  • tells the function to give a value back to wherever the function was called from
  • return; (ends the function without returning a value, used in void functions)

That's a basic example. Here's the code I was struggling to understand:

========================================================

#include stdio.h (use <> around stdio.h)

int strawberry(int leaves);
int pies(int crusts);

int main(void)
{
     int apple = 3;
     int orange = 12;
     apple += strawberry(orange);
     printf("apple: %d\n", apple);
     apple += pies(7);
     printf("apple: %d\n", apple);
     return 0;
}
int strawberry(int leaves)
{
     int rc = leaves*2;
     rc += 5;
     printf("strawberry rc = %d\n", rc);
     return rc;
}

int pies(int crusts)
{
     int rc = crusts;
     rc += strawberry(crusts % 5 + 2);
     printf("pies rc = %d\n", rc);
     return rc;
}

================================================

Functions:

strawberry
pies
strawberry

Parameters:

leaves
crusts
leaves

Arguments Passed:

orange -> 12
7
crusts % 5+ 2 -> 4

Arguments are the actual values you pass in when you call the function

Parameters are the placeholders that exist in the function definition to receive those values

=================================================

What I think is happening in the program:

  1. Start
  2. DECLARE:
  3.      apple
         orange
  4. Call strawberry(orange) assign 12 to strawberry()
    1. call strawberry(int leaves) assign 12 to leaves
    2. leaves*2 = 24
    3. rc + 5 = 29
    4. print "strawberry rc = 29"
  5. back in main apple + strawberry() = 3 + 29 = 32
  6. print "apple: 32"
  7. Call pies(7)
    1. call int pies(int crusts) assign 7 to crusts
    2. rc += strawberry(crusts % 5 + 2) = rc += strawberry (2+2 = 4)
    3. call strawberry(4)
      1. inside strawberry(4)
      2. leaves = 4
      3. rc = 4*2=8
      4. rc += 5 = 8 + 5 = 13
      5. print "strawberry rc = 13"
      6. return 13 to caller (pies)
    4. rc += strawberry = 7 += 13 = 20
    5. print "pies rc = 20"
    6. return 20 to caller main
  8. apples += pies() = 32 + 20 = 52
  9. print "apple: 52"
  10. End

Final Output:

strawberry rc = 29
apple: 32
strawberry rc = 13
pies rc = 20
apple: 52

=================================================

As you can see, this is so confusing. I'm so confused. 😂 I sorta got it but I don't feel comfortable with it. Definately need more practice. The first half is understandable but when it gets to pies() I loose all hope. I do at least hope this entry can be a good ref for me to come back to. Otherwise, I think it's time to solve some other examples...Wish me luck!

Next Journal >>>