I need to do this do while loop but I dont know how to exactly get it to repeat itself I got an error when I tried to compare pointer to integer and thats what i have in the code below, any thoughts as to how this should be done.

do
{
        cout << "Enter your address starting with your name then street then city then state then zip code, seperate each section with a space and then a # the immediatly following the # enter the next set ...

        cin.getline (name, 20, '#');
        cin.getline (street, 20, '#');
        cin.getline (city, 20, '#');
        cin.getline (state, 20, '#');
        cin.getline (zip, 7, '.');

        cout << "The address that you entered is:\n";
        cout << name;
        cout << "\n";
        cout << street;
        cout << "\n";
        cout << city;
        cout << ",";
        cout << state;
        cout << zip;

        cout <<"Would you like to enter another address y/n?";
        cin >> repeat;
}while(repeat != 'n');

Recommended Answers

All 6 Replies

First off fix this

cout << "Enter your address starting with your name then street then city then state then zip code, seperate each section with a space and then a # the immediatly following the # enter the next set ...

add " and a ; at the end

also add 'N' as option in cause the user enters it as caps.

What is the data type of 'repeat'? It should be a char for your while condition to work.

Val

Is using '#' to deliniate lines required by the assignment or is it something you dreamed up on your own?

while( cin >> name >> street >> city >> state >> zip)
{

}

Is using '#' to deliniate lines required by the assignment or is it something you dreamed up on your own?

while( cin >> name >> street >> city >> state >> zip)
{

}

Will that work for:
John Smithers 2031 West Alberta Street Sioux Falls South Dakota 65565? What will be in zip? :icon_rolleyes:

Will that work for:
John Smithers 2031 West Alberta Street Sioux Falls South Dakota 65565? :icon_rolleyes:

Yup, works for that too! It just won't give the OP the result he wants :)

while( getline(cin,name) )
{
    getline(cin,street);
    // etc
}

i ended up getting it to work about 2 am west coast time so I went to bed, thanks for the input guys and just to clarify the assignment did ask for the # signs to seperate the different sections and all i needed to do to fix what I had for it to work was to put double quotations around the n instead of single quotations, simple fix and i realize my way may not have been the proffesional way of doing it but hey I'm a beginner and if it compiles and runs how I want I am very happy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.