Write a program to take input for two integer variables. Assign the value -1 to the variable with higher value using a function.
[Use return by reference ]
#include <iostream>
void ChangeHigherValue(int& a, int& b)
{
if(a > b)
{
a = -1;
}
else
if(a < b)
{
b = -1;
}
}
int main()
{
int a, b;
std::cout << "Input for two integers: ";
std::cin >> a >> b;
if(!std::cin)
{
std::cout << "Error: invalid data\n";
return 1;
}
ChangeHigherValue(a, b);
std::cout << "a = " << a << "\n";
std::cout << "b = " << b << "\n";
return 0;
}
Comments
Thank you so much Assignment expert
Leave a comment