Thread: Try As I Might, Please Help:

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    7

    Question Try As I Might, Please Help:

    I am stuck on a question found in the book Jumping into C++ by Alex Allain.
    Chapter 4 question 4: Expand the password checking program from earlier in this chapter and make it take multiple usernames, each with their own password, and ensure that the right username is used for the right password. Provide the ability to prompt users again if the first login attempt failed...
    I am able to create a successful one user and password checker but (I can't seam to figure out how to make it work for at least 2 people.) I skipped it and move on to loops and succeeded in the Bottles of Beer project and remembered that I still had to expand the above password project. My problem is I keep mixing up and miss calling int or strings and I don't understand how to use getline in a multiple option for the user. *** Any ideas or help on keeping them straight please?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You should post your latest code attempt - don't forget the [code][/code] tags.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2017
    Posts
    7
    Thank You In Advance For Your Time & Patience It Is Much Appreciated!!!

    here is my latest attempt:

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
       int name=Nate;
       int name=Ange;
       int password="123";
       int password="321";
       string login=Nate&&"123";
       string login=Ange&&"321";
       
       //getline and structure maybe??
       do
       {
           cout<<"Enter User Name: "<<endl;
           cin>>name;
           cout<<"Enter User Password: "<<endl;
           cin>>password;
       }while !(login)

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Two variables can NOT use the same name/identifier in the same scope.

    Have you learned about arrays?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Mar 2017
    Posts
    7
    Sorry for the second code post guys... I'm trying to keep the message board as clean as I can by reusing the same code section but I am limited on how soon I can revise it. Here is my revised try in response to stahta01 I have not learned about arrays yet
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
       int user1=Nate;
       int user2=Ange;
       int password1=123;
       int password2=321;
       string user1&&password1;
       string user2&&password2;
       //getline and structure maybe??
       do
       {
           cout<<"Enter User Name: "<<endl;
           getline(cin>>user1,user2);
           cout<<"Enter User Password: "<<endl;
           getline(cin>>password1,password2);
       }while !(user1,password&&user2,password2)

  6. #6
    Registered User
    Join Date
    Mar 2017
    Posts
    7
    Please note: I want to correct line 19 to }while !(user1,password1&&user2,password2)

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Nate and Ange are not numbers!

    Please try compiling your code!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Post your code for a Single user because I do NOT think you know enough to do that based on the C++ like code you have posted.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  9. #9
    Registered User
    Join Date
    Mar 2017
    Posts
    7
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
        string username;
        string password;
        do
        {
        cout<<"Enter your username: "<<endl;
        getline(cin,username,'\n');
        cout<<"Enter your password: "<<endl;
        getline(cin, password,'\n');
        }while (!(username == "Nate" && password == "123"));
        cout<<"Access allowed "<<endl;
        cin.ignore();
        cin.get();
    }
    Here is my single user password checker and its loop to give the user infinite attempts to get it right but that only solves the second part of the question I'm stuck on. I don't understand why Alex is suggesting to do something in the practice problems that hasn't been taught thoroughly yet...

  10. #10
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    How about
    Code:
    do
    {
      // read user and pass, then ...
    
    }while (!(user == "A" && pass == "1") &&
            !(user == "B" && pass == "2") &&
            !(user == "C" && pass == "3"));

  11. #11
    Registered User
    Join Date
    Mar 2017
    Posts
    7
    Oh My Word!!! Thank you sooo much @ algorism You Have Helped Me So Much (rolls eyes at self and palms face) I can't Believe it was as simple as the Boolean operators. But that was exactly what I was struggling with "structure of the Boolean operators" if you will. Thank YOU, thank you, thank you. Now I have closure and can move on in my learning

Popular pages Recent additions subscribe to a feed

Tags for this Thread