-
September 29th, 2010, 08:30 AM
#1
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.
-
September 29th, 2010, 08:53 AM
#2
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 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.
-
September 29th, 2010, 10:39 AM
#3
Re: Error in function 'int main()":
changePassword is a member of class UserAccount. You're not using it that way.
-
September 29th, 2010, 11:08 AM
#4
Re: Error in function 'int main()":
Originally Posted by GCDEF
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.
-
September 29th, 2010, 12:00 PM
#5
Re: Error in function 'int main()":
Originally Posted by Eialvare
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.
-
September 29th, 2010, 12:58 PM
#6
Re: Error in function 'int main()":
it runs but the if statement in main doesnt work
-
September 29th, 2010, 01:04 PM
#7
Re: Error in function 'int main()":
Have you fixed the login() function as monarch_dodra (and the compiler, no doubt) instructed you yet?
-
September 29th, 2010, 01:10 PM
#8
Re: Error in function 'int main()":
yes i fixed that part already
-
September 29th, 2010, 01:11 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|