cant get the info displaying - PLEASE HELP

i cant get the dob and scores to display right and also the question do you want to search for student doesnt work right. The yes option works but if i say no it just searches anyway. Im reading from a text file and i want to enter the student number and all their info comes up
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "stdafx.h"
using namespace std;

const int NUM_SCORES = 6;
typedef struct 
{
	int day;
	int month;
	int year;
} Date;
struct Student 
{
	int number;
	Date dob;
	float scores[NUM_SCORES];
} ;

Student studentsList[15];
Date date [15];
int entries;
int counter1=0, counter2=0, counter3=0;

void readStudent (Student student[], int &entries);

void BinarySearch (Student list[], int& item, bool& found);
int ForgetfulBinarySearch (Student list[], int& item, bool& found);
int REBinarySearch (Student list[], int& item, bool& found);

int _tmain(int argc, _TCHAR* argv[])
{
readStudent (studentsList, entries);

bool found = false;
char response;

do
	{
for (int i=0; i < entries; i++)
{

	cout << "Enter a Student number: " << endl;
	cin >> studentsList[i].number;
	BinarySearch(studentsList, studentsList[i].number, found);
	ForgetfulBinarySearch(studentsList, studentsList[i].number, found);
	REBinarySearch(studentsList, studentsList[i].number, found);

	cout << "DOB: "<< studentsList[i].dob.day << "/" << studentsList[i].dob.month << "/" << studentsList[i].dob.year << endl;
	cout << "Exam Results: "<< studentsList[i].scores[0] << " " << studentsList[i].scores[1] << " " << studentsList[i].scores[2]
	<< " " << studentsList[i].scores[3] << " " << studentsList[i].scores[4] << " " << studentsList[i].scores[5] << endl;
	cout << "Binary Search = " << counter1 << endl;
	cout << "Forget search = " << counter2 << endl;
	cout << "RE search = " << counter2 << endl;

cout << "Do you want search for student?(Y/N):";
		cin >> response;
	}

}
	while ((response=='Y')||(response=='y'));
return 0;
}

this isnt all the code but hopefully someone can help me with this part.
dont worry about the binary searches and counter stuff i just help displaying DOB and scores. The problem is that no matter what number i enter it will just display the first line of info from the file, if i enter another number it will display the second line etc
The number i enter doesnt match the info from the file
Last edited on
anyone?
Last edited on
The yes option works but if i say no it just searches anyway
The reason for that is you don't break the loop on line 38 if not 'Y'/'y' entered.

The problem is that no matter what number i enter it will just display the first line of info from the file, if i enter another number it will display the second line etc
That's because you're using the loop index 'i' for showing the data. The binary search functions should return the index found and that index is what's supposed to be used on line 47 and following.
Topic archived. No new replies allowed.