J
John J
Thanks for the help in my previous thread, I was able to solve the problem
by using some code I'd written into another function. For anyone interested
I've included the working code in my last thread.
I've now written some similar code to search for the winner of a race. The
"entries" in the code below is a pointer to an Entry. Below is the code I've
written to search for the winner, which works by checking if (Pl == 1);
however, I'm not sure how to implement this correctly. Further below my non
functioning code is a copy of the constructor I've used in the Entry class.
Could someone please have a look at my if/else function and advise where I'm
going wrong.
Thanks for any help.
void Race::winner (ostream& out) const
{
if (nEntries == 0) //nEntries is initialised to zero in the constructor
{
out << "No entries" << endl;
}
else
{
for (int i=0; i<nEntries; i++)
if (Pl == 1) //This is where I need help ..... I think....
{
out << *(entries);
}
else
{
cout << "There was no winner in this race" << endl;
}
}
}
// Constructor from Entry class
Entry::Entry (Race* r, Yacht* y, int pl, string ti)
{
which = r;
what = y;
place = pl;
time = ti;
}
by using some code I'd written into another function. For anyone interested
I've included the working code in my last thread.
I've now written some similar code to search for the winner of a race. The
"entries" in the code below is a pointer to an Entry. Below is the code I've
written to search for the winner, which works by checking if (Pl == 1);
however, I'm not sure how to implement this correctly. Further below my non
functioning code is a copy of the constructor I've used in the Entry class.
Could someone please have a look at my if/else function and advise where I'm
going wrong.
Thanks for any help.
void Race::winner (ostream& out) const
{
if (nEntries == 0) //nEntries is initialised to zero in the constructor
{
out << "No entries" << endl;
}
else
{
for (int i=0; i<nEntries; i++)
if (Pl == 1) //This is where I need help ..... I think....
{
out << *(entries);
}
else
{
cout << "There was no winner in this race" << endl;
}
}
}
// Constructor from Entry class
Entry::Entry (Race* r, Yacht* y, int pl, string ti)
{
which = r;
what = y;
place = pl;
time = ti;
}