question on VOID swapping

Hello im in an intro to c++ class and we were discussing void swapping which barely made any sense for me.

The professor gave us an example that swaps 2 numbers order
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
void swap(double& a, double& b);
int main()
{
 double A, B;
cout << "Enter 2 numbers:";
cin >> A >> B;
swap(A, B);
cout << "A = " << A << endl;
cout << "B = " << B << endl;
return 0;
}
void swap(double& a, double& b)
{
 double temp;
temp = a;
a = b;
b = temp;
return;
}


this gives me:
original
A=4
B=5

new
A=5
B=4


My question is how do I use the void function in order to swap 3 numbers' position
ex.
original
A=2
B=3
C=4

new
A=4
B=2
C=3
Last edited on
I did it, unfortunately, the console keeps on closing even with the system("pause");

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
#include <iostream>
using namespace std;
void swap(double& a, double& b, double& c);
int main()
{
	double A, B, C;
	cout << "Enter 3 numbers:";
	cin >> A >> B >> C;
	swap(A, C);
	swap(B, C);
	cout << "A = " << A << endl;
	cout << "B = " << B << endl;
	cout << "C = " << C << endl;
	return 0;
}
void swap(double& a, double& c, double& b)
{
	double temp;
	double dits;
	temp = a;
	a = c;
	c = temp;

	system("pause");
	return;
}


any ideas?
thanks
Topic archived. No new replies allowed.