How can I solve this problem
Jul 20, 2013 at 6:39pm UTC
So this is the code I wrote
Main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <string>
#include "login.h"
using namespace std;
int main(){
login obj;
system("PAUSE" );
return 0;
}
login.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#ifndef LOGIN_H
#define LOGIN_H
#include <string>
#include <iostream>
using namespace std;
class login{
public :
login();
void setUsername(){
username = "Username" ;
};
void setPassword(){
psword = "Password" ;
};
int getUsername(string US_n){
int a;
if (US_n == username)
a=0;
else
a=1;
return a;
};
int getPassword(string US_p){
int a;
if (US_p == psword)
a=0;
else
a=1;
return a;
};
private :
string username;
string psword;
};
#endif
login.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include "login.h"
#include <iostream>
#include <string>
using namespace std;
login::login(){
int a,b;
string us_name;
string pd;
cout << "Username: " ;
cin >> us_name;
cout << "Password: " ;
cin >> pd;
cout << endl;
a = getUsername(us_name);
b = getPassword(pd);
if ( a==0 && b==0)
cout << "You are now logged in!" << endl << endl;
else
cout << "Wrong username or password!" << endl << endl;
}
It doesn't show any error when I compile it but when I run doesn't metter if I used the right or wrong username and password, it always shows the message "Wrong username or password!". How can I solve it
Jul 20, 2013 at 8:50pm UTC
You never call setUsername and setPassword. I recommend making them constructors, rather than having the login proc be the constructor.
Topic archived. No new replies allowed.