Thread: First password program

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    13

    First password program

    Hey, i made this password program but i am having trouble getting it to work. the last thing i need to do it be able to compare the inputed password to the actual password (in this program i want it to be "matt") im not sure how i do this, could someone help? with this code i get undefined symbol 'matt' when i try to compile with borland. i know why i just dont know how to fix it :S

    Code:
    //Passwod Program
    //By Matt
    
    #include <iostream>
    
    using namespace std;
    
    int main() {
    
    char password[5];
    
    
    start:
    
    cout<<"* * * * * * * * * * * * * \n";
    cout<<"  Please enter your PIN   \n";
    cout<<"-------   4 letters  ------ \n";
    cout<<"* * * * * * * * * * * * * \n";
    
    cin.getline (password, 5, '\n' );
    
    if(password == matt ) {
    cout<<"Thank You! \n";
    
    }
    else {
    
    cout<<"Sorry Incorrect PIN \n";
    goto start;
    }
    
    }
    Last edited by MaaaTtY; 02-14-2009 at 10:32 AM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    // Password Program
    // By Elysia
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        std::string password;
        const std::string correct_password = "matt";
        do
        {
            cout << "* * * * * * * * * * * * * \n";
            cout << "  Please enter your PIN   \n";
            cout << "-------   4 letters  ------ \n";
            cout << "* * * * * * * * * * * * * \n";
            getline(cin, password);
    
            if (password != correct_password)
                cout << "Sorry Incorrect PIN \n";
        }
        while (password != correct_password);
    
        cout << "Thank You!\n";
    }
    I figured it was easier to show REAL code instead of explaining all the wrong's with your code. Now it's your task to find out why I wrote it the way I did and what's wrong with your approach.
    Last edited by Elysia; 02-14-2009 at 12:28 PM. Reason: Compile errors - begone!
    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.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    13
    haha thats funny, thanks alot though, it will definetly help alot :]

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    13
    i tried to compile yours and i got this error:

    could not find a match for 'getline<charT,traits,Allocator><string,istream>' in function main()

  5. #5
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Make sure you:
    Code:
    #include <string>
    The other problem is getline, it should be:
    Code:
    getline(cin,password);
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Good corrections... didn't test to compile the code. It's easy to miss a few things here and there.
    I updated the original post to fix those errors... it's good to have a compilable example!
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  4. Beginner needs help with password program
    By dnottus in forum C++ Programming
    Replies: 6
    Last Post: 04-22-2002, 06:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM