logic of boolean

I wrote a function that checks for duplicate numbers within an array.

Could someone please explain how the logic of true/false actually works?

What would be the outcome if I set my initial dup variable to false and had it changed to true when a duplicate was found?

1
2
3
4
5
6
7
8
9
10
11
12
bool NoDuplicates(int ticket[SIZE], int number, int currentSize)
{
	bool dup = true;

	for (int x = 0; x < currentSize; x++)
	{
		if (ticket[x] == number)
			dup = false;
	}

	return dup;
}
Last edited on
Hi,

bool is essentially true/false or 0/1, just think of it as a flag which when evaluated to condition becomes true or false

your output will totally depend upon your function call

hope it helps :)
Topic archived. No new replies allowed.