I'm having some trouble on a HW assignment. I'm not asking for a full solution (I'm not even telling you the assignment). What I do want to know is how the heck my output is changing! Please note the code below:
from main.cpp:
Function a.
Function b.
Output:
In the first case, you can see that the number 4831293 is returned just fine. However, for 9984631, it inexplicably changes to '2', everytime I run. I've tried a number of fixes, but none of them really fixed anything. Any idea what the heck is going wrong?
from main.cpp:
Code:
number = A.getNumber("Mendoza", "Charles");
number = A.getNumber("Chaplain", "Johnny");
Function a.
Code:
// getNumber
int Book::getNumber(string lname, string fname)
{
int temp;
temp = getNumber(lname, fname, root);
cout << "outcheck" << endl;
cout << temp << endl;
return temp;
}
Function b.
Code:
// getNumber
int Book::getNumber(string lname, string fname, Card* card)
{
if((lname == card->contact.getLast()) &&
(fname == card->contact.getFirst()))
{
int number = card->contact.getNumber();
cout << number << "~" << endl;
return number;
}
else
{
if(lname < card->contact.getLast())
{
getNumber(lname, fname, card->lchild);
}
else if(lname > card->contact.getLast())
{
getNumber(lname, fname, card->rchild);
}
else if(fname < card->contact.getFirst())
{
getNumber(lname, fname, card->lchild);
}
else if(fname < card->contact.getFirst())
{
getNumber(lname, fname, card->rchild);
}
else
{
cout << "ERROR: Name not found." << endl;
}
}
}
Output:
Code:
4831293~
outcheck
4831293
9984631~
outcheck
2
In the first case, you can see that the number 4831293 is returned just fine. However, for 9984631, it inexplicably changes to '2', everytime I run. I've tried a number of fixes, but none of them really fixed anything. Any idea what the heck is going wrong?