How would I pass by reference?

I believe I passed by value instead of reference.

#include <iostream>
using namespace std;

float ADD();
float SUBTRACT();
float MUTIPLY();
int num1, num2;

int main()

{

int choice = 0;
int total = 0;
float a, b, c;
int num = 0;
//Menu Chooser
//Choose the type of loop you want to use to average this program



cin >> num1 >> num2;
cout << "OPERATIONS\n\n";
cout << "1 - ADD\n";
cout << "2 - SUBTRACT\n";
cout << "3 - MUTIPLY\n\n";
cout << "4 -Exit\n\n";


cout << "Choice: ";
cin >> choice;

// Demonstrates the switch statement.
//Pick a loop.
{
switch (choice)
{
case 1:
{
//ADDITION
a = ADD();
cout << "\You have chosen to ADD.";
cout << "\The sum is:" << a;

}
break;

case 2:

{

//SUBTRACTION
b = SUBTRACT();
cout << "\You have chosen to SUBTRACT.";
cout << "\The difference is:" << b;
}

break;

case 3:
{
//MUTIPLICATION
c = MUTIPLY();
cout << "\You have chosen to MUTIPLY.";
cout << "\The product is:" << c;

}
break;


case 4:
{
cout << "Goodbye";
}
break;

default:
{
cout << "You made an illegal choice.\n";
}
break;
}

}

return 0;
}
float ADD()

{


//This is ADDITION.
float SUM;
//SUM
SUM = num1 + num2;
return SUM;

}

float SUBTRACT()
// SUBTRACT
{
float Difference;
Difference = num1-=num2; //SUBTRACTION
return Difference;
}


float MUTIPLY()
{
//MUTIPLY
float PRODUCT;
//PRODUCT.
PRODUCT = num1*=num2;
return PRODUCT;


}
You didn't pass by value or reference. You used global variables which are horrible practice! Unless their constant don't use global variables!

This would be passing by value:
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream> 
using namespace std;

float ADD(int, int);
float SUBTRACT(int, int);
float MUTIPLY(int, int);

int main()

{

	int choice = 0;
	int total = 0;
	float a, b, c;
	int num = 0;
	int num1, num2;//num1 and num2 go in main
	//Menu Chooser
	//Choose the type of loop you want to use to average this program



	cin >> num1 >> num2;
	cout << "OPERATIONS\n\n";
	cout << "1 - ADD\n";
	cout << "2 - SUBTRACT\n";
	cout << "3 - MUTIPLY\n\n";
	cout << "4 -Exit\n\n";


	cout << "Choice: ";
	cin >> choice;

	// Demonstrates the switch statement. 
	//Pick a loop.
	{
		switch (choice)
		{
		case 1:
		{
			//ADDITION
			a = ADD(num1, num2);
			cout << "\You have chosen to ADD.";
			cout << "\The sum is:" << a;

		}
		break;

		case 2:

		{

			//SUBTRACTION
			b = SUBTRACT(num1, num2);
			cout << "\You have chosen to SUBTRACT.";
			cout << "\The difference is:" << b;
		}

		break;

		case 3:
		{
			//MUTIPLICATION
			c = MUTIPLY(num1, num2);
			cout << "\You have chosen to MUTIPLY.";
			cout << "\The product is:" << c;

		}
		break;


		case 4:
		{
			cout << "Goodbye";
		}
		break;

		default:
		{
			cout << "You made an illegal choice.\n";
		}
		break;
		}

	}

	return 0;
}
float ADD(int num1, int num2)

{


	//This is ADDITION.
	float SUM;
	//SUM
	SUM = num1 + num2;
	return SUM;

}

float SUBTRACT(int num1, int num2)
// SUBTRACT
{
	float Difference;
	Difference = num1 - num2; //SUBTRACTION // to many equal signs
	return Difference;
}


float MUTIPLY(int num1, int num2)
{
	//MUTIPLY
	float PRODUCT;
	//PRODUCT.
	PRODUCT = num1 * num2;// to many equal signs
	return PRODUCT;


}


and this would be passing by reference:

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream> 
using namespace std;

void ADD(const int &num1, const int &num2, float &SUM);
void SUBTRACT(const int &num1, const int &num2, float &Difference);
void MUTIPLY(const int &num1, const int &num2, float &PRODUCT);

int main()

{

	int choice = 0;
	int total = 0;
	float a = 0, b = 0, c = 0;
	int num = 0;
	int num1, num2;//num1 and num2 go in main
	//Menu Chooser
	//Choose the type of loop you want to use to average this program



	cin >> num1 >> num2;
	cout << "OPERATIONS\n\n";
	cout << "1 - ADD\n";
	cout << "2 - SUBTRACT\n";
	cout << "3 - MUTIPLY\n\n";
	cout << "4 -Exit\n\n";


	cout << "Choice: ";
	cin >> choice;

	// Demonstrates the switch statement. 
	//Pick a loop.
	{
		switch (choice)
		{
		case 1:
		{
			//ADDITION
			ADD(num1, num2, a);
			cout << "\You have chosen to ADD.";
			cout << "\The sum is:" << a;

		}
		break;

		case 2:

		{

			//SUBTRACTION
			SUBTRACT(num1, num2, b);
			cout << "\You have chosen to SUBTRACT.";
			cout << "\The difference is:" << b;
		}

		break;

		case 3:
		{
			//MUTIPLICATION
			MUTIPLY(num1, num2, c);
			cout << "\You have chosen to MUTIPLY.";
			cout << "\The product is:" << c;

		}
		break;


		case 4:
		{
			cout << "Goodbye";
		}
		break;

		default:
		{
			cout << "You made an illegal choice.\n";
		}
		break;
		}

	}

	return 0;
}
void ADD(const int &num1, const int &num2, float &SUM)

{

	//SUM
	SUM = num1 + num2;

}

void SUBTRACT(const int &num1, const int &num2, float &Difference)
// SUBTRACT
{
	Difference = num1 - num2; //SUBTRACTION // to many equal signs
}


void MUTIPLY(const int &num1, const int &num2, float &PRODUCT)
{

	//PRODUCT.
	PRODUCT = num1 * num2;// to many equal signs


}


In this example, I changed everything to be passed by reference but everything does not have to be passed by reference.
Thanks so much!
However is there anyway I can pass by reference without using void?
im dumb

tdog: start your own thread and state there what is your problem, delete the above posts
Topic archived. No new replies allowed.