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