Thread: Noobie ?

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    4

    Noobie ?

    hey guys!! First of all I hope there isn't a post like this, if so sorry for making a new one!! I'm a new programmer and I'm teaching myself C++ and i'm making a Enter password program that will print out "Password is correct"!! if user entered it correctly, and if the user doesn't enter it correctly then it automaticly starts the program over and gives the user 3 trys. If the users doesn't get it in 3 trys the it print out " Try again later!!" then closes the program!! This is all I have so far!!
    Code:
     #include <iostream>
    using namespace std;
    int main ()
    {
        
        string password = "03j14a86c";
        string UserInput;
        
            cout << "Please inter your password!!" << endl;
            
            cin >> UserInput;
            
    if (UserInput == password)
    {
                  cout << "Password is correct!!" << endl;
                  }
                  
                  else 
                  {
                       
                       }
                       
                       return(0);
    thanks for any help!! Jake

  2. #2
    Registered User
    Join Date
    Jun 2013
    Posts
    4
    suppose to be enter not inter in the code!!

  3. #3

  4. #4
    Registered User
    Join Date
    Jun 2013
    Posts
    4
    sorry I have looked at your link but I still can't get it to do right. I'm getting it to run but its not doing right. Can you show me how? Here is an update of my code:
    Code:
      #include <iostream>
    using namespace std;
    int main ()
    {
        
        string password = "03j14a86c";
        string UserInput;
        
            cout << "Please enter your password!!" << endl;
            
            cin >> UserInput;
            
    if (UserInput == password)
    {
                  cout << "Password is correct!!" << endl;
                  }
                  
                  else 
                  {
                       cout << "Password not correct!!" << endl;
                       }
                       
                       for ( int x = 1; x <= 3; x++);
                       {
                             }
                             
                             cin.get();
                             cin.get();
                       return (0);

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Start by making a flowchart. Mesh out the logic on how you want to approach this.
    A little better indentation wouldn't hurt, either.
    Oh, and don't use semicolons after for loops, or any other kind of loop.
    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.

  6. #6
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    Ok so first of all you don't need to define the password as a string and then make the comparison, it's kind of a waste of code, unless you are going to use it somewhere else. You're better off comparing it right away. Eg:
    Code:
     If (UserInput == "03j14a86c")
    2) Instead of
    Code:
     cin >> UserInput
    , try
    Code:
     getline(cin, UserInput)
    That way, the whole lne will be "read" and your program won't assume you inserted 2 passwords in case you insert a space while typing it.

    3) In order to provide the user with 3 tries, you need to make a loop. Personally I'm used to while loops in this kind of situations. Eg:
    Code:
    while(NumberOfTries != 3)
    {   
        if(/*Your comparison*/)
       { 
           cout << "The password is correct";
           break;   
       }
    }
    Now add yourself what you think that should be added in order to make it work.
    Last edited by Khabz; 06-08-2013 at 04:15 AM.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Khabz View Post
    Now, in order to make it work ... Hope that helped.
    Don't hand out solutions. If the OP cannot figure out how to make a simple loop, the OP cannot do programming.
    That is why the OP must be taught on how to make loops, which usually accounts to seeing how to connect the logic, which flowcharts helps with. Simply saying "do this and that" will not help the OP see HOW to construct loops in general.
    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.

  8. #8
    Registered User
    Join Date
    Jun 2013
    Posts
    4
    ok thanks for the help khabz!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some help for a Noobie!
    By barryr in forum C Programming
    Replies: 22
    Last Post: 11-29-2009, 08:59 AM
  2. Else if noobie trouble
    By Swerve in forum C++ Programming
    Replies: 10
    Last Post: 11-18-2007, 09:07 AM
  3. Noobie Little Help Please
    By Mike1982 in forum C Programming
    Replies: 2
    Last Post: 09-18-2007, 10:34 PM
  4. i admit im a noobie
    By tommytomthms5 in forum C Programming
    Replies: 10
    Last Post: 06-04-2006, 02:06 AM
  5. help me im a C++ noobie!!!
    By fatso in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2002, 10:14 AM