bug

hh
Last edited on
array/vector index should go from 0 to size-1
1
2
3
	for (i = 0; i < Data.size(); ++i)
	{
		Data[i] = rand() % 2;
I
Last edited on
You are still using indexes from 1 to size() when you should start at 0 and stop when reaching size().
Last edited on
when I use index zero the result of my code will be wrong
In what way is it wrong?
in the result, I must have a sequence of binary numbers in each line, but if I change the range of i, it returns a strange and weird numbers!!!
Not sure I understand, but if you use i for other things where you need it to start counting from 1 you can just use (i+1) in those places.

 
std::cout << "Value " << (i + 1) << " is " << Data[i] << ".\n";

If you prefer you can use a variable.

1
2
int num = i + 1;
std::cout << "Value " << num << " is " << Data[i] << ".\n";
Topic archived. No new replies allowed.