mercredi 22 juin 2016

How to reverse the order of string names?

I'm supposed to be able to enter in a set number of names, and then display them in the order of them being typed, "Our contestants printed Forwards". After which would be displayed in the reverse order, "Our contestants printed Backwards". I managed to get the "Forwards" part working, but am not sure how to get the "Backwards" part to work. I've commented out the copied code because I was using it as a placeholder.

To be fair, I'm supposed to be using the pointer that I defined, string *pNames, in order to do the storing and printing. But I have absolutely no idea how that is supposed to be done.

I would appreciate any and all help that I can get on this one. Thank you.

int main()
{
    string *pNames;

    string names[3];

    pNames = names;

    for (int counter = 0; counter < 3; counter++)
    {
        cout << "Please enter contestant number " << counter + 1 << " > ";
        getline(cin, pNames[counter]);
    }

    cout << "Our contestants printed Forwards" << endl;
    for (int i = 0; i < 3; i++)
        cout << pNames[i] << endl;

    cout << endl;

    cout << "Our contestants printed Backwards" << endl;
    //for (int i = 0; i < 3; i++)
        //cout << pNames[i] << endl;

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire