here is my code which needs to make a check about a student by his faculty number, and if there is no information to say that …
cout<<"Enter faculty number of the student(8 digits): "<<endl;
cin>>ch;
cout<<"Information about student with number:"<<ch<<endl;
for(i=0;i<n;i++)
{
if(m[i][0]==ch)
{
for(j=0;j<4;j++)
cout<<setprecision(8)<<m[i][j]<<"\t";
}
else if(m[i][0]!=ch)
{
cout<<"No information about this student"<<endl;
}
}
it works mostly fine, the problem is that if my “n”(number of student typed out of this code) is 3 … we will have 3 student and the cycle “for” will be made 3 times .. and we type 1 student (actually we are typing 1 faculty number) when i start the program it says whole information about that student and on two new lines it says “No information about this student”.
I cant put the IF check out of that FOR with N because i need to roll the m[i]… thanks
I have a few suggestions for this code.
1) Checking
m[i][0] == chafter locating the entry only makes sense if a student is expected to have multiple entries. I suspect not, in which case you should make the loop break as soon asm[i][0] == ch.2)
cout<<"No information about this student"<<endl;shouldn’t be in the loop because it will printn - 1times (ifchis indeed a valid ID,ntimes otherwise). Make the related check afterwards.