Helloeveryone,
I don't understand an exercise in my book. What he want me to do?
4. Write a function that takes two input arguments and provides two separate results to the caller, one
that is the result of multiplying the two arguments, the other the result of adding them. Since you can
directly return only one value from a function, you'll need the second value to be returned through a
pointer or reference parameter.
I code like that but I dont know if it is right answer:
#include <iostream>
int addAndMultiply( int a, int b, int& prod )
{
prod = a*b ;
return a+b ;
}
int main()
{
int a, b ;
std::cout << "Enter a number: " ;
std::cin >> a ;
std::cout << "Enter another number: " ;
std::cin >> b ;
int product ;
int sum = addAndMultiply(a, b, product) ;
std::cout << "Sum: " << sum ;
std::cout << "\nProduct: " << product << '\n' ;
}
@senhor
I knew its not about the memory but you should not give out false information. Be 100% sure because a small problem can cause other problems...
People just have their own ways
@senhor
I knew its not about the memory but you should not give out false information. Be 100% sure because a small problem can cause other problems...
senhor didn't give false information. He said he thought that was the reason and we have no reason do doubt he didn't think so.