How to use a value in a fuction in another fuction

^ Question :)
Last edited on
Pass the value to the function as an argument.
define value,
are you talking about local variables or function arguments?

btw, local variables in one function can not be used in other function, unless you call the other function with local values as arguments.
That is what Peter said I think?
Last edited on
You have two functions f(x) and g(x). You want f(x) to be 3 times g(x). Define it like this: f(x) = 3g(x). It's the same in programming.

1
2
3
4
5
6
7
8
9
10
11
12
13
double g(double x) {
    //...
}

double f(double x) {
    return 3 * g(x); //pass x to g as an argument
}

//Or, did you mean composition of functions?
// (If the return type of the inner matches the argument type of the outer.)
double h(double x) {
    return f( g(x) );
}
Topic archived. No new replies allowed.