sara1: i still do not know what's problem with my code
The problem is with your logic in the code. In words it reads:
"For all existing students of previously added for a given exam, test each and every one for the following conditions: If the exam is registered for the proposed new student, say "error". If the exam is not registered, do and say "added".".
The problem is that since you check each and every one for the "not registered", the only case where this test will not evaluate to true at least once in the loop is if the only previously added student/exam is the same as you try again with.
If you have a group of students, and you ask each and every one of them "are you Dave", you'll find that at most one will actually be Dave - but all but at most one will not be! (Provided the student population only has one Dave, but since the assumption here is that the student id is unique, we'll asssume that there's only one Dave for this example.
The code proposed will ask each student until either "Dave" is found (already added), or all have been asked, and none was "Dave". Only when you have asked all, and got a negative answer for each and every one do you know that the one you're looking for is not there - but as soon as you find one that answers to "Dave", you know that you found (someone already added).
Hope this makes it clearer.
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager -
http://www.axantum.com[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.