the below code is working fine if the user enters the USN number that he has already entered.
but again if he enters the same USN number one mare time that is accepted. i tried checking the
USN number using infinite loop (;;), but i don’t know how to exit from the infinite loop.
Is there any solution for it. or please suggest me how to terminate the infinite loop.
void student :: GetData()
{
cout<<"Enter the number of students record wolud you like to enter(10 records as MAX): ";
cin>>MAX;
cout<<"\n Now enter the "<<MAX<<"students records\n";
student so[10]; // SO is Student Object
int i;
for(i=0;i<MAX;i++)
{
cout<<"Enter the Name: ";
cin>>so[i].name;
cout<<"\nEnter the USN num.: ";
cin>>so[i].USN;
for(int k=1;k<i;k++)
{
if (so[i].USN == so[k].USN); // here it finds the if the entered USN number exist or not
{
cout<<"The USN number exist try new one: ";
cin>>so[i].USN;
} // But after this statement if he enter the same exist USN number is accepting
//I need you guys to help me out at this point
}
cout<<"\n Enter the Three Marks: ";
for(int j=0;j<3;j++)
{
cin>>so[i].marks[j];
}
}
}
Do this:
And you had a syntax problem there