Search function

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;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top