Thread: when i run the program windows says "7-pass.exe has stopped working".

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    15

    when i run the program windows says "7-pass.exe has stopped working".

    i named the program 7-pass.cpp.
    Modify your password program from before to put all of the password checking logic into a
    separate function, apart from the rest of the program.
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    string passcheck(string check)
    {
        string pass;
        pass=("abcd");
        if(pass==check)
            {
                cout<<"access granted!";
            }
        else
            {
                cout<<"acess denied!";
            }
    }
    int main()
    {
        string password;
        cout<<"enter your password:\n";
        cin>>password;
        cout<<passcheck(password);
    }
    the program runs and displays the results correctly but everytime it shows 7-pass.exe has stopped working.is something wrong?

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Does this happen when you run the program by itself, or when you run it through your IDE?
    Devoted my life to programming...

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    why are you tryuing to run program before you have fixed all teh errors?

    test.cpp: In function ‘std::string passcheck(std::string)’:
    test.cpp:16:1: warning: no return statement in function returning non-void [-Wreturn-type]
    }
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Apr 2015
    Posts
    15
    @greaper when i run it through an IDE.

    @vart when i compile it doesn't show any error :/.

  5. #5
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by recklezz View Post
    @greaper when i run it through an IDE.

    @vart when i compile it doesn't show any error :/.
    What compiler are you using, again ?

    Your function 'passcheck' ought to return a value but it does NOT.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    when i compile it doesn't show any error
    But you should be getting a warning as shown in post#3.
    test.cpp:16:1: warning: no return statement in function returning non-void [-Wreturn-type]
    If you're not getting a similar warning then you need to see about increasing your compiler warning level so that it can better help you find the problems.

    If you are getting any warnings, you should always fix the warnings. In most cases warnings should be treated as errors and always fixed.

    Jim

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    As said, you're not returning anything from passcheck, and since you're trying to output whatever is returned, you're landing in undefined land. Fix it and your problem goes away.
    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. Replies: 2
    Last Post: 12-23-2012, 04:52 AM
  2. Replies: 3
    Last Post: 11-22-2007, 12:58 AM
  3. how can i pass by reference by "malloc 2d array"?
    By Mathsniper in forum C Programming
    Replies: 10
    Last Post: 05-22-2005, 02:23 PM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM