- A function has got to funct, it's that IO thing again,
sure, avoid function as necessary,
and obviously valid, but most functions chew on input,
and do something based on that input.
In this movie, I explore how functions can deal
with arguments or values passed to the function.
You'll see how to declare such a function,
how it deals with values, and how to pass more
than a single value to a function.
This code contains the repeat function,
which accepts one argument, an integer.
Within the function, the integer variable is named count.
The function is called at lines eight and 10.
Each time, with a different argument.
Inside the function, a local variable, x, is declared.
It's used in the four statement, along
with a count variable, build and run this code.
The function can also accept integer variables as arguments.
Make these modifications to the code.
In the main function, declare integer variables a and b.
Assign the value 1 to a, and 5 to b.
Use a and b in the two repeat functions.
Save the changes, build and run, and the output is the same.
Open exercise file argument two.
In this code, you see a function
that accepts three arguments.
In this case, three floating point values.
The scanf function at line 10,
reads in the three values, this is possible,
providing you format the input to match the format string.
In the product function, the product of the three values
is calculated and displayed. Build and run this code.
I'm going to type 12, 13, and 15.
And there's the result.
There is no limit to the number of arguments
a function can accept, although the more arguments,
the more likely it will be to mess up the format.
Functions don't necessarily need to eat
all the same argument type, either.
Open exercise file argument three.
The bar function accepts two arguments.
A character, an integer value. Build and run this code.
The bar function uses both of its arguments
to output a bar of a certain character across the display.
Open exercise file argument four.
This file contains an empty function evaluate.
Your job is to complete the function.
It should accept an integer value,
and display a message stating whether the value
is less than, greater than, or equal to 10.