ready function but not woking properly

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
Looks fine to me.
It won't close the infile. You may want to put infile.close() before each return statement.
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
i remove return; but still now not output any thing
What is the actual problem? You never did say.

http://www.cplusplus.com/forum/articles/1295/
Topic archived. No new replies allowed.