Need some help with a homework question

NOTE: Pass by value only.

Assume that your program has a main() function, an enterAge() function, and a birthday() function.

The main() method will call the enterAge() with no parameters; the enterAge() will return the age entered by the user.

The main() method then passes the age to the birthday() function as the only parameter.

The birthday() function increments the age by one, and returns the incremented age to the main() function via the return statement.

Code the prototype for the enterAge() function as it would appear in the main() function.

Code the call statement as it would appear in the main() function, which invokes the enterAge() function and captures the value (the age) returned by the enterAge() function.

___________________________________________________________________________

Im having trouble understanding the concept of parameters and how the birthday function can increment the age one by one.
so the enterAge() protoype would be

enterAge()
{
int age;
cout << "What is your age?";
cin >> age;

}
No.

The prototype would be:
 
int enterAge(); // Prototype simply gives the return type (int), the name (enterAge) and the parameters (none). 

The function itself had the same signature as the prototype but also contains a function body:
1
2
3
4
5
6
7
8
int enterAge() // Definition contains the actual function
{
    int age;

    // ... get age from user

    return age; // return age from this function
}
Last edited on
Topic archived. No new replies allowed.