Mar 30, 2010 at 12:00pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
void FindStud(int SID[],string FNAME[],string MAJOR[],float GPA[],int HRS[])
{
int id;
ifstream infile;
infile.open("studinput.txt" );
cout << "enter the id:" ;
cin >> id;
while (id)
{
while (!infile.eof())
{
infile >> SID[i];
if (id == SID[i])
{
cout << setw(10) << "Student ID:" << setw(9) << SID[i] << "\n" ;
cout << setw(10) << "First Name:" << setw(10) << FNAME[i] << "\n" ;
cout << setw(5) << "Major:" << setw(14) << MAJOR[i] << "\n" ;
cout << setw(3) << "Gpa:" << setw(16) << GPA[i] << "\n" ;
cout << setw(13) << "Total Credits:" << setw(5) << HRS[i] << "\n" ;
return ;
}
else
cout << "wrong id" << endl;
}return ;
}
infile.close();
}
the output looks like this
Enter the id: 5555
Student Id: 5555
First Name: Nasir
Major: Physics
Gpa: 2.56
Total Credits: 85
this is the infile
1111 Hamad Comp 3.25 110
5555 Nasir Physics 2.56 85
2222 Laila Math 2.30 89
1200 Amal Comp 1.99 120
4444 Yahia Comp 2.67 56
Last edited on Mar 30, 2010 at 12:05pm UTC
Mar 30, 2010 at 1:23pm UTC
It won't close the infile. You may want to put infile.close() before each return statement.
Mar 30, 2010 at 2:38pm UTC
There shouldn't be any return statements in the body of the function.
EDIT: Technically they can be there (now I see that I overlooked they are empty) but I don't think your intention was to use them. Didn't you want to use continues/breaks instead?
Last edited on Mar 30, 2010 at 5:44pm UTC
Mar 30, 2010 at 3:29pm UTC
i remove return; but still now not output any thing