float array[100];
Is there a way to take the array above a use the [100] in sequence? such as a having it check to see if [0] is used and if so then move on to [1] and so on...
any help would be appreciated.
float array[100];
Is there a way to take the array above a use the [100] in sequence? such as a having it check to see if [0] is used and if so then move on to [1] and so on...
any help would be appreciated.
Your question is confusing. You can use a for loop from 0 to 99 to access each element in the array in sequence. You could keep an extra variable to store how many in the array are used and stop when you hit that variable. You could also initialize the values to some number that you will never use and if the value is still that number when you loop through then you know the element is not being used (assuming there is a number like 0.0f that you don't need).
You could also use a vector and only fill it with the values that you need - so if you are only using 27 elements, only add 27 elements, and if you need to use one more, just push_back a new one.
I've opted to use vectors and maps for anything that is variable in size or is primarily a lookup for medium-large lists of information. I've used vectors that had only one dimension, like a vector of strings, and I've used vectors that were struct-based. Adding items is easy, searching for items is easy, it's all easy. For what it's worth, if you've never worked with vectors, try it this time in place of your array.
Floats usually have NaN values, which you can get with numeric_limits.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law