A set could be useful here. When the user enters an ID, try to insert it to the set.
You can tell wether or not the operation was successful by looking at its return value.
#include <iostream>
#include <set>
usingnamespace std;
int main()
{
set<int> numbers;
int n;
while (true)
{
cout << "enter a number (0 to quit) -> ";
cin >> n;
if (n==0) break;
if (numbers.insert(n).second==false)
cout << "you've already entered ";
else
cout << "this is the first time you enter ";
cout << n << endl;
}
cout << "\n(hit enter to quit...)";
cin.get();
cin.get();
return 0;
}
Yes or you could avoid cin.clear and cin.ignore() by entering the student ID into a vector or array and then looping through the container to find a duplicate and then accept or reject.