Password code

This is a discussion on Password code within the C++ Programming forums, part of the General Programming Boards category; Ok heres the deal, i decided to wright this simple little code were user inputs a password and has the ...

  1. #1
    Motor head pre-programmer
    Join Date
    Aug 2004
    Posts
    8

    Password code

    Ok heres the deal, i decided to wright this simple little code were user inputs a password and has the choice to log in. Ive looked through it for syntax errors and can figure out whats wrong. Ive only been doing c++ for a couple of weeks now so its very hard for me to spot it myself.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
      string access;
      string guess;
      int choice;
    
      cout<<"Please create the passcode: ";
      cin>>access>>endl;
    
      cout<<"Great you have now created an acount."<<endl;
      cout<<"Log in? Yes (1)/ No (2)."<<endl;
      cin>>choice;
      
      if (choice == 1){
      cout<<"Please enter passcode: ";
      cin>>guess;
        
        if (guess == access){
        cout<<"Welcome to your acount Dustin"<<endl;
        }
        
        else
        cout<<"Sorry wrong passcode, program terminating."<<endl;
        }
      
      else
      cout<<"Good bye"<<endl;
     
     return 0;
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Your placement of brackets varies at a couple places (based on your indentation of code) but this should not affect the correctness of the program. What is the specific problem you are having?

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
      string access;
      string guess;
      int choice;
    
      cout<<"Please create the passcode: ";
      cin>>access>>endl;
    
      cout<<"Great you have now created an acount."<<endl;
      cout<<"Log in? Yes (1)/ No (2)."<<endl;
      cin>>choice;
      
      if (choice == 1){
      cout<<"Please enter passcode: ";
      cin>>guess;
        
        if (guess == access){
        cout<<"Welcome to your acount Dustin"<<endl;
        }
        
        else{
        cout<<"Sorry wrong passcode, program terminating."<<endl;
        }
      }
      else
      cout<<"Good bye"<<endl;
     
     return 0;
    }
    Last edited by hk_mp5kpdw; 08-25-2004 at 02:13 PM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Wrong:
    Code:
      cin>>access>>endl;
    change to
    Code:
      cin>>access;

    Dave

  4. #4
    Motor head pre-programmer
    Join Date
    Aug 2004
    Posts
    8
    Well at first there were specific problems when compiling it, but i eventualy got rid of all that (things like syntax errors and stuff). Now when i try to compile it, i just get back a bunch of random things (atleast it looks like it to me) like this:

    C:/MinGW/include/c++/3.2.3/istream:255
    std::basic_istream<char, _Traits>& std:perator>> <std::basic _istream<char, _Traits>&, signed char*> [with _Traits = std:: char_ Traits<char>]

    I get that and things very similar to that over and over again.

    I realy have no clue what that means and i dont realy know enough about c++ to know if my source code will work or if i have to do it some other way.

  5. #5
    Motor head pre-programmer
    Join Date
    Aug 2004
    Posts
    8
    Ok when i just got done writing that dave posted
    it worked, i figured you needed the >>endl; so that it wouldnt keep going on the same line, Thanks

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by muralemerica
    Well at first there were specific problems when compiling it, but i eventualy got rid of all that (things like syntax errors and stuff). Now when i try to compile it, i just get back a bunch of random things (atleast it looks like it to me) like this:

    C:/MinGW/include/c++/3.2.3/istream:255
    std::basic_istream<char, _Traits>& std:perator>> <std::basic _istream<char, _Traits>&, signed char*> [with _Traits = std:: char_ Traits<char>]

    I get that and things very similar to that over and over again.

    I realy have no clue what that means and i dont realy know enough about c++ to know if my source code will work or if i have to do it some other way.
    This is the kind of messages you get when it is trying to compile this c++ program as a c program

    (From the command line use g++, not gcc).

    Your original post compiled OK after I made the change that I mentioned previously.

    Dave

  7. #7
    Motor head pre-programmer
    Join Date
    Aug 2004
    Posts
    8
    Ok, i dont know if anyone is reading this post anymore but i hope so.
    I farthered the code of my password thing, and of course, im stuck again. My compiler sais that i have a parse error before else on line 34 and that "statement cannot resolve adress of overloaded function" (line 35) The thing is, i didnt think i used overloading functions.
    Code:
    #include <iostream>    
    #include <string>    
    using namespace std;
    int main()	
    { 		
      string access = "thekillers"; 	
      string farther = "muralemerica";	
      string guess;		
      string thought;		
      string name;
      int choice;							        
      
      cout<<"Please enter your name: ";
      cin>>name;
      cout<<"Please enter passcode: ";	
      cin>>guess;				
        				
        if (guess == access){		
        cout<<"Welcome to your acount "<<name<<endl;		
        cout<<"Your contents can be found at: ";			
        cout<<"C-UT2004DEMO-Help-exconfig-Document1.txt"<<endl;
        cout<<" "<<endl;						
        cout<<"Proceed to excess contents? This will require a"<<endl;  
        cout<<" level 2 access code. Yes (1)/No (2): ";		    
        cin>>choice;						    
        							    
          if (choice == 1){						    
          cout<<"Enter Level 2 passcode: ";   			    
          cin>>thought;  						    
          							    
             if (thought == farther){				    
             cout<<"Access granted, welcome to your arcive files"<<endl;      
    
             cout<<name<<endl;    
             
             else
             cout<<"Wrong passcode, program terminating.";endl; 
             }	    
             							    
          else
          cout<<"Good day "<<name<<endl;				    
          }								    
        
        else							    
        cout<<"Sorry wrong passcode, program terminating."<<endl;       
        }								    
     return 0;
    }

  8. #8
    Registered User
    Join Date
    Jan 2004
    Posts
    24
    It compiles fine. I believe all your errors were simple ones you need to avoid. You need to close the if BEFORE using else example:
    Code:
        if(this == 1){
            do-this;
        } else {
            do-that;
        }
    almost all of your if statments had this problem. Here is the fixed code:
    Code:
    #include <iostream>    
    #include <string>    
    using namespace std;
    int main()	
    { 		
      string access = "thekillers"; 	
      string farther = "muralemerica";	
      string guess;
      string thought;
      string name;
      int choice;
      
      cout<<"Please enter your name: ";
      cin>>name;
      cout<<"Please enter passcode: ";
      cin>>guess;
    
        if (guess == access){
        cout<<"Welcome to your acount "<<name<<endl;
        cout<<"Your contents can be found at: ";
        cout<<"C-UT2004DEMO-Help-exconfig-Document1.txt"<<endl;
        cout<<" "<<endl;
        cout<<"Proceed to excess contents? This will require a"<<endl;  
        cout<<" level 2 access code. Yes (1)/No (2): ";
        cin>>choice;
    
          if (choice == 1){
          cout<<"Enter Level 2 passcode: ";
          cin>>thought;
    
             if (thought == farther){
                 cout<<"Access granted, welcome to your arcive files"<<endl;      
    
             cout<<name<<endl;    
            } 
             else {
                 cout<<"Wrong passcode, program terminating." << endl; 
             }	    
    
          } else {
              cout<<"Good day "<<name<<endl;
          }
        
        } else {
            cout<<"Sorry wrong passcode, program terminating."<<endl;       
        }
     return 0;
    }
    Last edited by linuxman; 08-25-2004 at 07:29 PM.

  9. #9
    Motor head pre-programmer
    Join Date
    Aug 2004
    Posts
    8
    Oh, ok i get it now, besides the fact of forgetting to put <<endl; i didnt have the brackets right. I couldnt completely figure out how to deal with them thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 02:42 AM
  2. Saving my Password in a file
    By Yuri in forum C++ Programming
    Replies: 29
    Last Post: 08-09-2005, 05:33 PM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  4. Replies: 4
    Last Post: 01-15-2002, 11:04 PM
  5. help on code
    By TED22_8 in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2001, 10:21 AM

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