Also notice the omission of the equal sign in mutexe's correction. This is important because it is what actually stops you from over running your array.
Depending on your skill level, you may want to also check out the range based for-loops implemented in C++-x11. You should get the basics like this down first but after that, this is a useful tool to save yourself some typing: http://en.cppreference.com/w/cpp/language/range-for
actually i want to generate distinct random numbers every time say between 1 to 30.
but it actually is not doing the same....so i am trying to replace the redundant nos by another random no...also i do not want to start the i from 0 because there is no use of that number it is just to make sure that j does not take a negative value that is -1 which it can take up according to this program.
i want to store all the random numbers and then i want to use the array for displaying random questions based on the numbers stored that is why i am not starting with 0.
and yes it worked when i removed the equal sign but can u tell me why?
it worked when i removed the equal sign but can u tell me why?
You allocated 120 elements in your array. Those elements are numbered [0] to [119]. If you attempt to reference [120], you're referencing an element that is out of bounds.
BTW, your line 29 will also index past the end of the array.