hello I'm am needing help with some code I wrote that reads a text file of 1000 most popular female names and sorts them for the user to enter a name and outputs its popularity number. I need to have the program keep asking the user to enter names until stop is entered and I am unsure how to do this. Also I am told my program has memory access errors becuase This got memory access errors because it tried to referenced femnames[1000] which doesn't exist, i dont understand as i have femnames[SIZE] in which SIZE=1000. below is my code, any help would be appreciated.
> keep asking the user to enter names until stop is entered while(cin >> searchKey and searchKey not_eq "stop")
> it tried to referenced femnames[1000] which doesn't exist, i dont understand as i have femnames[SIZE] in which SIZE=1000.
first element is femnames[0]
last element is femnames[999]
valid index goes from 0 to size-1
Thank you so much for your help on the while statement but Im not sure what you mean by your response to the femnames issue. Im sorry im still new to all this and have a hard time understanding.
The first element in the array is the one at offset zero from the beginning of the array.
For example, in the array of 5 elements int a[5]
The first element exists exactly at the beginning of the array - that is, zero elements offset from the beginning of the array, and is so named a[0].
The fifth element exists at an offset of four elements from the beginning of the array; that is, it has four elements before it, and therefore the last element in the array is named a[4].
It is forbidden to access a[5], because that would access at the sixth element in a five element array.