Thread: Simple Password Crash

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    1

    Simple Password Crash

    Hello All,

    I've been working through the book and have recently finished the chapter on functions. The problem I'm having is working practice problem three. I don't know why but my program keeps crashing every time I try and run it.

    Code:
    #include <iostream>#include <string>
    
    
    using namespace std;
    string check(string x, string y);
    
    
    int main()
    {
        string username, password;
        char choice;
        for(;;)
        {
            cout << "Password Checking Program!" << endl;
            cout << "Please enter your username and password: ";
            cin >> username >> password;
            cout << endl;
    
    
            check(username, password);
    
    
            cout << "Press c to continue and q to quit.";
            if(choice == 'c')
            {
                continue;
            }
            else if(choice == 'q')
            {
                break;
            }
            else
            {
                cout << "I don't know what you wish to do returning to the program." << endl;
            }
        }
        return 0;
    }
    
    
    string check(string x, string y)
    {
        if(x == "root" && y == "password")
        {
            cout << "Access granted." << endl;
        }
        else
        {
            cout << "Please try again." << endl;
        }
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    If you increase the warning level of your compiler, it will likely tell you what is wrong. Hint: you're telling the compiler that check() will return a string.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Aug 2015
    Posts
    2
    I'm going to take a shot in the dark and say that the reason why your program is crashing is because the "check" function is supposed to return a string, yet it returns nothing.

  4. #4
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Also it looks like 'choice' is uninitialized, did you mean to call the >> operator to fill it in?
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-29-2014, 02:08 AM
  2. Simple password program
    By BIGDENIRO in forum C Programming
    Replies: 4
    Last Post: 11-18-2013, 02:07 PM
  3. Simple password system
    By ex-mortis in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2012, 10:56 AM
  4. simple crash problem (exiting func)
    By te5la in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2008, 03:15 PM
  5. what is causing this seemingly simple app to crash?
    By Shadow12345 in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 08:36 PM