When calling a function that has requirements received in other functions, is it better or worse to have a function call for one of the requirements in a general function call?
I demonstrated this simple example:
int amountToMultiplyBy(int multiplyAmount)
{
int temp;
std::cout << "how much do you want to 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, the call amountToMultiplyByis within the call sumOfNumbers, receiving a value for multiplyAmountduring the call.
In version 2, it amountToMultiplyByis called first, giving multiplyAmountits value, which is then included in the call sumOfNumbers.
I'm just curious to know if this is good practice, bad practice or just the exact same?
source
share