Functions

7.1 - Function intro


A function is a reusable piece of code. For example you can create a function that calculates the average of given numbers, a function that prints out a string, or a function to retrieve information from a web page. One thing to keep in mind when creating a function is that the function should only have one job.

Here is an example of a function in C++ :

int sum(int a, int b) {
    return a + b;
}

This functions takes two integers as the argument and returns a single integer which is the sum. You can use it like this.

int main() {
    std::cout << sum(5, 8) << std::endl; // Prints out 13.
}

Your task is to create the function called product which accepts two integers and return a single integer which is the product of the inputs.

Note: you should not write the main function. The test cases will define their own main function.

Sample input code

#include <iostream>

int main() {
    std::cout << product(5, 8) << std::endl;
}

Sample output

40
// Define your product function here!