Click to See Complete Forum and Search --> : debugging stump


Indiana Jonethon
02-24-2001, 07:10 AM
I'm working on a programming project at school. The following is the client
part:

reg.inspect_student(pname0);
cout<<pname0;

cout<<"****************************";
'pname0' is not in the list and it is supposed to output:

Student not found. Please try again
fred
***********************


Instead I get I get the following:

fred
***********************
Student not found. Please try again.


I have also included the class function that is being called:

void registrar::inspect_student(char* pname)
//print out (to the screen) all information for a student with "name"
//Print out: name, gpa, number of courses taken
{
char get_name[30];

if (name_is_found(pname))
{
students[location].get_name(get_name);
cout << "\nName: ";
for (int i=0; i<30; i++)
{
cout << get_name[i]; //outputs name found.
if (get_name[i] == '\0')
i = 30;
}

cout << "\nStudent's current GPA: ";
students[location].calc_gpa(); //calculate GPA
cout << students[location].gpaIs(); //display GPA

cout << "\nNumber of courses taken: ";
cout << students[location].num_courses_is() << endl;
}
}
bool registrar::name_is_found(char* qname)
//find location of "qname" in location array
{
bool more_to_search = true;
location = 0;
char get_name[30];

students[location].get_name(get_name); //get name at location
while ((strcmp(qname, get_name))&&(more_to_search))
//compare each name and loop till one condition is false
{
location++;
if (location == num_students)
{
more_to_search = false;
cout << "\nStudent not found. Please try again.\n";
}
students[location].get_name(get_name); //get name at
//location
}

if (location != num_students)
return true;
else
return false;
}