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");
}
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...
Re: Error in function 'int main()":
changePassword is a member of class UserAccount. You're not using it that way.
Re: Error in function 'int main()":
Quote:
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")
Re: Error in function 'int main()":
Quote:
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.
Re: Error in function 'int main()":
it runs but the if statement in main doesnt work
Re: Error in function 'int main()":
Have you fixed the login() function as monarch_dodra (and the compiler, no doubt) instructed you yet?
Re: Error in function 'int main()":
yes i fixed that part already
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.