I need to create void function called "swapPositive" which takes two reference parameters and swaps the values in those parameters if they are both positive numbers.
Show how this function is called from a main() program.
This is what I have so far.
#include <iostream>
void swap_if_positive( int& a, int& b ) // note: a and b are of type 'reference to int'
{
if( a > 0 && b > 0 ) // if both are positive
{
// swap them
constint temp = a ;
a = b ;
b = temp ;
}
}
int main()
{
int a, b ;
std::cout << "\nPlease Enter the value of a and b\n" ;
std::cin >> a >> b ;
std::cout << "\nBefore Swap: a = " << a << " and b = " << b << '\n' ;
swap_if_positive( a, b ) ; // pass references to a and b
std::cout << "\nAfter Swap: a = " << a << " and b = " << b << '\n' ;
}