I am supposed to write a function name double_swap that takes two doubles as arguments and interchanges the values that are stored in those arguments. The function should return no value, so I know that means it must be a void function.
For example, if the following code fragment is executed,
int main() { double x = 4.8, y = 0.7; double_swap(x,y); cout<<"x = "<<x<<" y = "<<y; } The output will be: x = 0.7 y = 4.8
The program I wrote is not swapping the values. I'd greatly appreciate if someone could point out my errors.
#include <iostream> using namespace std; void double_swap(double x, double y) { x = 1.9; y = 4.2; } int main() { double x = 4.2, y = 1.9; double_swap(x,y); cout<<"x = "<<x<<" y = "<<y<<endl; return 0; }