Functions are useful because the help break your code up into smaller pieces, which improves readability and reusability. Lemme elaborate on that.
In cases where you have to perform the same action several times at different points in a program (that a loop is insufficient for), then a function can be invaluable.
In other cases, a loop can still help make your program easier to read (which is a benefit for you and whoever might read your code) by taking blocks of code which serve a specific purpose out of main and putting them into their own function.
Finally, in cases where someone else might want to use your code in the form of a library (assuming they have your permission), then giving them functions to work with that can be easily integrated into their program is one of the ways you can let them use it.
Now to respond to your assignment.
I think those functions were meant to take in fahrenheit and celsius values in parameter and return celsius and fahrenheit values respectively. You've got the "return" bit down fine, but they still need to take parameters.
Declaring that a function is going to take parameters is as simple as making a list of comma-separated variable declarations. Example:
some_obscure_type some_function(some_obscure_type a, some_obscure_type b, int generations, bool ignoreDiscrepencies);
Actually calling a function is similarly simple:
1 2 3 4 5 6 7 8
|
some_obscure_type rabbit, wolf;
bool doLongTerm = false;
//INSERT CODE THAT MANIPULATES THE ABOVE VARIABLES HERE.
some_obscure_type chimera;
if(doLongTerm)
chimera = some_function(rabbit, wolf, 1, false); //FUNCTION CALL!
else
chimera = some_function(rabbit, wolf, 70, true); //FUNCTION CALL!
|
Did this help at all?
-Albatross