Make a Function Inside the Code

In C, we use:

#include <stdio.h>
#include <cs50.h>

to tell the computer to access these libraries written by someone else at a previous time.

We use:

int main (void)

as a function. The left-side is the input. The right-side is the output.

The example I am working on today is as follows:

#include <cs50.h>
#include <stdio.h>
int main(void)
// This tells the computer there is function somewhere in the code and to look for it when executing the code.    
void cough (int n) 
        // Instead of this: int i = 0; i < 3; i ++
    // Making a function with an argument. I can use this function in the code. 
    // Left void = doesn't take an input. 
    // Right void = we tell it to give an output.
    void cough (int n)
         for (int i = 0; i < n; i ++)

Im a little confused? I am just setting the function and making the output (int n). So, I am setting the n value, then the code executes accordingly?

I’m not sure if I understand exactly.

I feel I am starting to understand things a little easier now. My brain usually stars at and copies examples then it starts understanding.

Practiced for 2 hrs today. Trying to do 2 hrs sessions Monday to Friday as the weekends are quite busy.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s