Sign in to follow this  
hothead

need some help with code

Recommended Posts

im trying to make program that lets you enter a word and delete word could someone help with my code but please don't give me the entire program
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main()
{
    list<string> words;
    do 
    {
        cout<<"do you want to enter a word yes(1),no(2)";
        if words = 1;
        
        cout<<"\nwhat word";
        int words insert();

Share this post


Link to post
Share on other sites
Even though you didn't post all of your code, I already found a few errors. I highly suggest you go over if loops and checking conditionals. Also, stay away from do loops - they're horrible.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Quote:
Original post by Ekim_Gram
Also, stay away from do loops - they're horrible.
Uh, no. They exist to ensure that the loops runs at least once, regardless of conditional.


Why use a do...while loop when you can just use a simple while loop? The do and the rest of the {}'s just seem to be a waste of a few seconds of typing.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ekim_Gram
Why use a do...while loop when you can just use a simple while loop? The do and the rest of the {}'s just seem to be a waste of a few seconds of typing.

Because you use a do while loop when the body has to always be run at least once. It's more clear if you use a do while loop. If you were to simulate that with a regular while loop, you would either have to introduce an unecessary condition, seed a condition to be true when it might not logically make sense to do so, or duplicate code prior to the start of a while loop. A do while loop makes more sense than any of the alternatives when the loop must always run at least once.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this