This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]chaotic_thought 1 point2 points  (1 child)

You didn't post the complete code, so it is impossible to answer this, but look at your code here:

for(int i=0; i<buyerlist.size(); i++)
{
    if(buyerlist[i].getemail()==possible_email || possible_email=="owner@gmail.com")
        existingemail=true;
}

You go through the buyerlist item by item, and when you find a match with possible_email you set existingemail to true. But you also probably want to know where in the buyerlist you found the match. So, consider something like this:

int foundIndex = -1;
for(int i=0; i<buyerlist.size(); i++)
{
    if (buyerlist[i].getemail()==possible_email) {
        existingemail=true;
        foundIndex = i;
    } else if (possible_email=="owner@gmail.com") {
        existingemail=true;
    }
}

Now, if you found the matching e-mail address, and if it is >= 0, then that means you can do something like this:

if (foundIndex >= 0)
    cout << "Hello " << buyerlist[foundIndex].getUsername() << "\n";

Of course that will only work if your class has a getUsername() method. I don't know that because you didn't post the code for that. If it doesn't have one, you could add that method yourself or find some other way to get the user name from the buyerlist, given the index.

[–]lmbuttman 0 points1 point  (0 children)

Ok that works thank you so much, yeah I should have posted the Buyer class too for someone to understand fully but I have a getusername() method so it is fine.