Let's look at int largest(int n1, int n2, int n3) part by part. The first word int simply means that the function will return an integer. largest is the name of the function. This is what you will use to call it in main. The int before each parameter specifies what the type of that parameter should be, in this case all integers. To use the function in main you use it's name and give it the right parameters then store the value in a variable or output it directly: int biggestNum = largest(45, 987, -29999);
P.S. To use largest in main, you must define the function before you define main. Or just put int largest(int, int, int); and then write the definition later.
The following two programs are equivalent in output:
1 2 3 4 5 6 7 8 9
// Example program
#include <iostream>
int main()
{
int a = 3;
int b = 2;
std::cout << "Sum: " << a + b << '\n';
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Example program
#include <iostream>
int sum(int a, int b);
int main()
{
int a = 3;
int b = 2;
std::cout << "Sum: " << sum(a, b) << '\n';
}
int sum(int a, int b)
{
return a + b;
}