bool isSame=false;
do
{
bool isSame=false;
for (int i=1; i<=corners; i++)
{
cout << "Please enter the cordinates for corner " << i << ':';
cin >> x[(i-1)] >> y[(i-1)];
}
int k;
for (k=0;k<(corners-1);k++)
{
int j;
for(j=(k+1);j<corners;j++)
{
if ((x[k]==x[j])&&(y[k]==y[j]))
{
isSame=true;
}
}
}
if (isSame==true)
{
cout << "One or more of the coordinates you have entered are the same."<<endl
<<"Please enter different coordinates."<<endl;
pause();
system("cls");
}
}while (isSame==true);
Above is code I have written that allows a user to enter some coordinates and then checks to ensure they are not the same. The issue I am having is that even though at the start isSame=true
when debugging the value is shown as false
.
I debugged with stop points at every point where isSame
is defined. At the first two outright declarations of false
, the debugger is showing true
. When it gets to isSame=true
it becomes false
. Then it reverts back to true and executes the cout statement. Finally it returns to false
and exits the do-while loop.
I have a feeling I am missing something very obvious but I can't seem to find it.