0

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?

2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by Hektzu
0

>>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.

0

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

0

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. -_-

Edited by Hektzu: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.