c++ - Getting the requirements for a function within the function call -


when calling function has requirements obtained in other functions, better or worse have function call 1 of requirements within overall function call?

i've made simple example demonstrate:

int amounttomultiplyby(int multiplyamount) {        int temp;     std::cout << "how want multiply by: ";     std::cin >> temp;     multiplyamount = temp;     return multiplyamount; } void sumofnumbers(int numone, int numtwo, int multiplyamount) {     std::cout << "1: " << numone * multiplyamount << std::endl;     std::cout << "2: " << numtwo * multiplyamount << std::endl; } 

main version 1:

int main() {     int multiplyamount;         sumofnumbers(5, 10, amounttomultiplyby(multiplyamount));     return 0; } 

main version 2:

int main() {     int multiplyamount;     multiplyamount = amounttomultiplyby(multiplyamount);     sumofnumbers(5, 10, multiplyamount);         return 0; } 

in version 1, call amounttomultiplyby within call sumofnumbers, obtaining value multiplyamount during call.

in version 2, amounttomultiplyby called first giving multiplyamount value, included in call sumofnumbers.

i'm curious know if either practice, bad practice, or same?

calling multiple functions parameters of function not practice. since cannot guarantee order of inner functions called. if inner functions have data dependency may creates bugs.

as said so, in case, since there no multiple functions calls function's parameter list either way go.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -