I am a bit confused regarding my program below. In my if statement, I am calling the boolean function twice. For the i, and j variable I spicked, the "else" statement should be executed as both function calls will yield true. But my "i" variable is not being modified (it outputs as 1001 instead of 1000), and I have no idea why. The j variable is being modified as expected. The first function call passes in "j" variable, and the second function call passes in "i" variable. Could someone explain why the "i" variable is not being modified?
#include <iostream>
using namespace std;
const int MINCOLOR = 0;
const int MAXCOLOR = 1000;
bool clipColor(int &amountColor);
int main()
{
int i=1001;
int j = 3333;
int k;
bool check;
if (clipColor(j) == false && clipColor(i) == false)
{
check = false;
}
else
{
check = true;
}
cout << i << " " << j << " " << check << " " << endl;
return 0;
}
bool clipColor(int &amountColor)
{
if (amountColor > MAXCOLOR)
{
amountColor = MAXCOLOR;
return true;
}
else if (amountColor < MINCOLOR)
{
amountColor = MINCOLOR;
return true;
}
else
{
return false;
}
}