Write the definition of a function named maxmin that is passed four int argument
ID: 3641325 • Letter: W
Question
Write the definition of a function named maxmin that is passed four int arguments. The function returns nothing but stores the larger of the first two arguments in the third argument it receives and the the smaller of the first two arguments in its fourth argument. So, if you invoke maxmin(3,7,x,y) , upon return x will have the value 7 and y will have the value 3.This is what I have and I know that it is wrong can some help me see what it is that I am doing wrong?
#include <iostream>
#include <cstring>
#include <cmath>
#include <iomanip>
void minMax(int&, int&, int&, int&);
void minMax(int &a, int &b, int &big, int &small)
{
if (a > b)
{
a = big;
}
else
{
b=big
}
if (a< b)
{
a =small;
}
else
{
b=small;
}
}
using namespace std;
int main ()
{
int parm1;
int parm2;
int parm3;
int parm4;
maxmin(parm1, parm2, parm3, parm4);
}
Explanation / Answer
In this case you need to treat a, b as constants and big, small as variables
You can't assign a variable to a constant, because you can't change the constant, ex: 0 = x
You can assign a constant to a variable, ex: x = 0
void minMax(int &a, int &b, int &big, int &small)
{
if (a > b)
{
big = a;
small = b;
}
else
{
big = b;
small = a;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.