if (choice == 1)
{//open if 1
clrscr();
cout << "Please enter your friend's name : ";
cin.ignore();
cin.getline(name,30);
cout << endl;
cout << "Please enter friend's IC number : ";
cin >> IC;
cout << endl;
cout << "Please enter your friend's address : ";
cin.ignore();
cin.getline(address,60);
cout << endl;
cout << "Please enter your friend's home phone number : ";
cin >> hpnum;
cout << endl;
cout << "Please enter your friend's office phone number : ";
cin >>opnum;
cout << endl;
cout << "Please enter your friend's mobile phone number : ";
cin >> mpnum;
break; //terminate loop if ic is matching with request
} //close if while 1
} //close while
if(infile.eof() && IC != requestIC)
{//open if while 2
cout << "No such IC " << endl;
} //close if while 2
infile.close();
cout << "Please press enter to continues... " << endl;
getch();
} //close if 2
}while (choice!=3);
if (choice == 3)
{
exit(1);
}
getch();
return 0;
}
This is a phone book program that could save and search for my friend's profile if i enter the proper IC number which is matching with the data saved in the "info.txt".That problem is that i can't understand with this lines of code "while(!infile.eof() )which is let me find the proper profile of my friend after the first few rows of information that had been saved.For example ,i had save profile a,b,c.If the ic number that i key in is match with profile b ,the information of profile b would prompt out properly.On the other hand ,if i remove the lines of while(!infile.eof() ),the program only let me display the profile a with ic number of profile a but found nothing for the profile b and c even key in the proper ic number which is suppose matching with them.