I have if statement which doesn't return true even though it should.

std::vector<__int64> numbers;

	for( __int64 i = 2; i < input; i++ )
	{
		numbers.push_back(i);
	}

	__int64 tmp = 4;

	for (unsigned int i = 0; i < numbers.size(); i++)
	{
		[U][B]if ( numbers[i] == tmp )[/B][/U]
		{
			numbers.erase(numbers.begin()+i);
		}
		tmp += 2;
	}

That particular line is underlined.

But if I do this it works.

for (unsigned int i = 0; i < numbers.size(); i++)
	{
		[U][B]if ( numbers[i] == 4 )[/B][/U]
		{
			numbers.erase(numbers.begin()+i);
		}
		tmp += 2;
	}

Where is the problem?

>>tmp += 2;
The first one doesn't work because the program keeps changing the value of temp on every loop iteration. Delete that line and the program will work.

But that is the idea of changin because next I'll check if(numbers = 6).
Where I should put the line?

I solved it.

for (unsigned int i = 0; i < numbers.size(); i++)
	{
		if ( numbers[i] == tmp )
		{
			numbers.erase(numbers.begin()+i);
                        [U][B]tmp += 2;[/B][/U]
		}
	}

Stupid mistake. -_-

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.