### Passing by reference, stuck.

Working on a pass by reference project. I am able to pass off the variables sum and product, but cannot for the life of me send and return the double quotient variable. What am I doing wrong?

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` `````` #include using namespace std; bool compute(int one, int two, int & sum, int & product, double& quotient); //intializing prototype void main() { int one, two, sum, product; double quotient; quotient = 0; cout << "Enter two integers: "; cin >> one >> two; if ( compute( one, two, sum, product, quotient) ) { cout << "\nSum: " << sum << "\nProduct: " << product << "\nQuotient: "<< quotient << endl; } else cout << "\nSum: " << sum << "\nProduct: " << product <<"\nThe quotient cannot be computed.\n" ; system("pause"); return ; } bool compute(int a, int b, int& sum, int & product, double& divided) { bool result = true; sum = a + b; product = a * b; if (b>0) { divided = (a)/(b); } else result = false; return result; } /* Enter two integers: 1 2 Sum: 3 Product: 2 Quotient: 0 Press any key to continue . . . */``````
a and b are integers, so a/b does integer division. Cast one to a floating point type before performing the division.

`divided = static_cast<double>(a)/b;`
Topic archived. No new replies allowed.