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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  #include <iostream>
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.