Jump to content
  • Advertisement
Sign in to follow this  
hothead

need some help with code

This topic is 4993 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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 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.

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
because do...while loops execute at least once. This is useful for checking input ie.

do
{
GetInput();
}while(InputIsInvalid());

Share this post


Link to post
Share on other sites
thanks for telling about my if statemebt it works now:) and im using a do loop so it will work at least once.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!