Search function

Discussion in 'C++' started by John J, May 7, 2004.

  1. John J

    John J Guest

    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;

    }
     
    John J, May 7, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=

    Google search result like site search!! How?

    =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=, May 5, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    715
    Lucas Tam
    May 6, 2005
  2. Andy
    Replies:
    1
    Views:
    374
    Jack Klein
    Nov 25, 2003
  3. Anand Pillai

    String search vs regexp search

    Anand Pillai, Oct 12, 2003, in forum: Python
    Replies:
    10
    Views:
    618
    Anand Pillai
    Oct 15, 2003
  4. mason66
    Replies:
    0
    Views:
    437
    mason66
    Jul 27, 2006
  5. Abby Lee
    Replies:
    5
    Views:
    475
    Abby Lee
    Aug 2, 2004
Loading...

Share This Page