When i try to run THIS PROGRAM
i get this error message: Illegal vector index: 100 max index = 99
what does this mean? how can i fix it?
thanks,
jason
When i try to run THIS PROGRAM
i get this error message: Illegal vector index: 100 max index = 99
what does this mean? how can i fix it?
thanks,
jason
the program is supposed to find the mode of the numbers in HERE (save the target as in the same directory as the cpp file) if you're trying to help
-jason
i am using Metrowerks CodeWarrior IDE version 5.0.0.951
Last edited by Maiq; 02-28-2003 at 01:49 AM.
as i quote...if you dont initialize variables..and use them they well contain junk values..look at this
you declare totNums, and mode as int and used them without initializing them...and in the function look at thisCode:int totalNums; int mode; LoadStats(list, totalNums); mode = FindMode(list, checkList, totalNums);
totNums = contain junk value..so you can loop more than the index value....Code:for(loop = 0; loop < totNums; loop++) { checkList[list[loop]]++; }
there might be more stuff wrong with your code..but i am sorry..too lazy to check
nextus, the samurai warrior
if list is and one dimensional array with 100 integers..and you set them all to 0 meaning they contain the value of 0 then
well just increment checkList[0] totNums time.....but since your totNums contain junk value..out of index :P give it a value!Code:for(loop = 0; loop < totNums; loop++) { checkList[list[loop]]++; }
nextus, the samurai warrior
heh, thanks nextus. but i found the answer shortly before you posted (then went sleep... zzzZzZZZZ) I had my checkList array (one dimensional, yes) set to 100 slots and I changed it to 101 and it worked. I guess when i tried to get all the data in the array with the loops it contained too little memory slots than needed (just one more!! :P)
Just to clarify, totalNums is initialized, since I pass by reference instead of value, and it gets it's value in the LoadArray function. And mode gets its value from FindMode function, you don't have to initialize a variable when you declare it, at least, that's what's been true in my experiences.
Thanks for your help!
-jason