Answer to Question #241692 in C++ for George

Question #241692

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 ]


1
Expert's answer
2021-09-25T05:57:13-0400
#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;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

George
06.10.21, 10:54

Thank you so much Assignment expert

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS