Like Tree3Likes

Loops

This is a discussion on Loops within the C++ Programming forums, part of the General Programming Boards category; Oh. Now that one makes sense. Thanks. Um. I guess I will show you what i thought was suppose to ...

  1. #16
    Rag
    Rag is offline
    Registered User
    Join Date
    Sep 2011
    Posts
    12
    Oh. Now that one makes sense. Thanks. Um. I guess I will show you what i thought was suppose to be for the password one, i know it is wrong but i did not know what else to do....

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
            string var;
            cout<<"Please enter the password."<<endl;
            cin>>var;
            while (var=="sad")    
            {
                   cout<<"You guessed that the password was "<<var<<" which was correct. Good job."<<endl;
                   var++;
           }
           
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  2. #17
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    No, while is not equivalent to if.
    In this case you need to repeatedly execute the portion where the user enters the password and it turns out to be wrong.
    Consider a freebie
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    int main()
    {
        string pass("your_pass"), temp;
        while(true)
        {
            cin>>temp;
            if(pass==temp)break;
            else cout<<"Try Again"<<endl;
        }
        //...other parts
        cin.get();
        return 0;
    }
    Last edited by manasij7479; 09-25-2011 at 02:35 PM.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #18
    Rag
    Rag is offline
    Registered User
    Join Date
    Sep 2011
    Posts
    12
    Okay.... I will go figure out how to do that.

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    Quote Originally Posted by CommonTater View Post
    Sometimes the best lessons are the least comfortable ones.
    Programming is not an area of expertise where one can "loaf along" and be good at it, it requires a certain analytical mindset... and you don't get that from Google.

    Offending post removed.
    I agree with you, but instead of being offensive, you can calmly state the facts and point to helpful resources.

    Rag,
    Do you have a basic understanding of what various loops there are in the language? If not, check out the lessons on this site.
    Afterwards, I think you should introduce yourself to flow charts. They are extremely good tools for newbies who have yet to grasp how to "naturally" translate logic into a programming language.
    Salem likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 06-01-2011, 04:19 PM
  2. loops, menu loops
    By gloworm in forum C Programming
    Replies: 17
    Last Post: 04-12-2010, 07:59 PM
  3. Help with C, loops
    By Bobbismal in forum C Programming
    Replies: 3
    Last Post: 09-12-2009, 06:07 AM
  4. help with loops
    By lpaolini436 in forum C Programming
    Replies: 8
    Last Post: 11-10-2006, 12:51 PM
  5. For Loops!!!
    By Nailogamer in forum C++ Programming
    Replies: 5
    Last Post: 08-14-2003, 06:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21