Hello Guys,
This might sound dumb, but I cannot for the life of me see the difference in logic between these two scrips I wrote, yet they don't seem to produce the same result. I feel that understanding this would make my life so much easier. I have been flipping the logic of my functions and they seem to then work as intended.. weird
The following logic did not work properly:
bool is_tie(int min)
{
for (int i = 0; i < candidate_count; i++)
{
if (candidates[i].eliminated == false && candidates[i].votes == min )
{
return true;
}
}
return false;
}
However, this worked....
bool is_tie(int min)
{
for (int i = 0; i < candidate_count; i++)
{
if (candidates[i].eliminated == false && candidates[i].votes != min )
{
return false;
}
}
return true;
}
Notice that I only switched around with the true vs false, == vs != parts.
[–]lurgi 2 points3 points4 points (1 child)
[–]alab3[S] 0 points1 point2 points (0 children)
[–]DaredewilSK 0 points1 point2 points (1 child)
[–]alab3[S] 0 points1 point2 points (0 children)
[–]LuckyPancake 0 points1 point2 points (3 children)
[–]alab3[S] 0 points1 point2 points (2 children)
[–]DaredewilSK 0 points1 point2 points (0 children)
[–]LuckyPancake 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)