c++ - getting a string to work in password function -


hi apologies poor explanation i'm new this. working on password function i'm having problems. have set account name string "john" , account password int 1111. password works fine string causing error. when change "const string name = "john"" random integer code works fine.

i hoping spot i'm going wrong?

bool login() {     const int password = 1111;     int passwordattempt;    const string name = "john";    string nameattempt;    int attempts = 0;     std::cout << "please enter password:" << std::endl; //first attempt @ account number & password    std::cin >> passwordattempt;    std::cout << "enter name:"<< std::endl;    std::cin >> nameattempt;  if (passwordattempt == password && nameattempt == name) {    return true;    }   else   while (passwordattempt!=password || nameattempt!=name) {      if(attempts++ ==2)//.. loop 2 more attempts      {        std::cout << "you have entered wrong details 3 times. application terminated now" << std::endl;        return false;        break;      }        std::cout<<"incorrect password. try again"<<std::endl;        std::cout<< "" <<std::endl;        std::cout << "please enter password:" << std::endl;        std::cin >> passwordattempt;        std::cout << "enter name:"<< std::endl;        std::cin >>nameattempt;      }       }     using namespace std;  int main() {  bool loggedin = login();  if (loggedin){ cout << "logged in" << endl; }  else if (!loggedin){ cout << "not logged" << endl; }  system("pause"); return 0; } 

  1. add std:: string declarations (so have std::string).
  2. after while loop there's end of function login without value return. add return true there. build warnings enabled!

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -