Hi. Hope it’s fine to seek help with other languages here, wasn’t sure where else to go.
Task:
“Given a vector of integers, determine how many integers are present before you see the value -99 . Note, it’s possible -99 is not in the vector! If -99 is not in the vector then the result will be equal to the number of elements in the vector.”
Why is it that these while loop conditions are valid:
while( index < vec.size() && vec.at(index) != -99 )
Also, in the future, more information would be helpful. What is the error? What is vec? Have you confirmed what the current state of vec is, logged it out? What is the rest of the code?
Thanks for your earlier response. So in the case of the error, the second condition is not evaluated (?). If so, should it not just return 0 as the answer? As expected? Regardless of the condition ordering, the loop wouldn’t execute and the program’s procedure should be the same?
vec is a vector, not an array: an array is something different and it would be incredibly confusing if the variable vec referred to an array (vectors are containers that grow dynamically, arrays are fixed size)