What is a function parameter?
A function parameter is a parameter between brackets after the identifier and is provided by the caller of a function.
If there is more than one parameter they are seperated by a comma.
Why do functions need parameters?
They allow us to create functions that take data as input, do some calculation with it, and return the value to the caller.
1) What’s wrong with this program fragment?
Void functions cannot return anything.
2) What two things are wrong with this program fragment?
Nothing is returned from the function.
Only one parameter is used in main()
3) What value does the following program print?
24
4) Write a function called doubleNumber() that takes one integer parameter
and returns twice the value passed in.
int doubleNumber()(int x)
{
return x * 2;
}
5) Write a complete program that reads an integer from the user
(using cin, discussed in lesson 1.3a – A first look at cout, cin, and endl),
doubles it using the doubleNumber() function you wrote for question 4,
and then prints the doubled value out to the console.
int doubleNumber(int x)
{
return x * 2;
}
int main()
{
int x;
std::cin >> x;
std::cout << doubleNumber(x) << std::endl;
return 0;
}