Error in function 'int main()":
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Error in function 'int main()":

  1. #1
    Join Date
    Sep 2010
    Posts
    34

    Error in function 'int main()":

    Can anyone tell me what this error is? Never saw it before my int main() is there but it keeps saying that. I also get changePassword was not declared in this scope , what does that mean?

    In function 'int main()':

    #include <iostream>
    #include <string>
    #include <fstream>
    using namespace std;

    class UserAccount
    {
    private:
    string userName;
    string userPassword;
    string userID;
    string password;
    string oldPassword;
    string newPassword;


    public:
    //constructor
    UserAccount ( string userID, string password)
    {
    userName = userID;
    userPassword = password;
    }

    //login
    bool login (string userID,string password)
    {

    if(userName == userID && userPassword == password)
    {
    cout << "True" << endl;
    }
    else {
    cout << "False" << endl;
    }

    } //end login


    //ChangePassword
    void changePassword ( string oldPassword, string newPassword)
    {
    if (oldPassword == password)
    {
    password = newPassword;
    }
    else {
    cout << "wrong" << endl;
    }
    }
    }; //end class

    int main ()
    {
    string userID;
    string password;

    UserAccount account (userID, password);

    cout << "What is your Username?" <<endl;
    cin >> userID; //user enter username

    cout << "Enter your Password?" <<endl;
    cin >> password; //user enter password


    if (account.login(userID, password))
    changePassword(password, "random_password");


    system("pause");
    }
    Last edited by Eialvare; September 29th, 2010 at 08:53 AM.

  2. #2
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,297

    Re: Error in function 'int main()":

    [CODE]code tags please[/CODE]

    What exactly is the error message? The ones I'm getting are pretty straight forward.

    Your "login" is still not returning a bool. You say it should, but I don't see a return anywhere in it. That is one of the more subtle problems.

    The other problems are big as trucks, and your compiler should tell you the problem in clear everyday English.

    EDIT:
    "In function 'int main()':" Means there is a problem in 'int main()'. Then, there's supposed to be the actual problem. Remember that an error message can span several lines...
    Is your question related to IO?
    Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,108

    Re: Error in function 'int main()":

    changePassword is a member of class UserAccount. You're not using it that way.

  4. #4
    Join Date
    Sep 2010
    Posts
    34

    Re: Error in function 'int main()":

    Quote Originally Posted by GCDEF View Post
    changePassword is a member of class UserAccount. You're not using it that way.
    What do you mean? I put it in the class section.

    Edit: okay so I see I have to do this right account.changePassword(password,"random password")
    Last edited by Eialvare; September 29th, 2010 at 11:37 AM.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,108

    Re: Error in function 'int main()":

    Quote Originally Posted by Eialvare View Post
    What do you mean? I put it in the class section.

    Edit: okay so I see I have to do this right account.changePassword(password,"random password")
    Try it and see.

  6. #6
    Join Date
    Sep 2010
    Posts
    34

    Re: Error in function 'int main()":

    it runs but the if statement in main doesnt work

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: Error in function 'int main()":

    Have you fixed the login() function as monarch_dodra (and the compiler, no doubt) instructed you yet?

  8. #8
    Join Date
    Sep 2010
    Posts
    34

    Re: Error in function 'int main()":

    yes i fixed that part already

  9. #9
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: Error in function 'int main()":

    Well then, breakpoint in the function and examine the variable values. That will let you know why you're seeing the behavior that you are.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center