Placing a login feature inside a menu (C++) -
i'm working on c++ project login system.
it seems have placed login feature on wrong side. since login system working, whenever want go menu, asks me login again? after each step asks me log in again.
how can fix this? aka: getting access full menu after succesfull login?
this code have:
char menuvesstock::menuvesstockoptions() { vestigingdao manager; string mgr_name, mgr_pass; cout << "\n\n * * * * - b r c o s t o c k m e n u - * * * *" << endl; cout << "please enter manager login" << endl; cout << "name: "; cin >> mgr_name; if (mgr_name.empty()) { return -1; } else { mgr_pass = hiddenline("password: "); vestiging* managermemb = manager.getmanagerbyname(mgr_name); if (managermemb == 0) { return -2; } else { if (managermemb->getmgr_pass() == mgr_pass) { cout << "welcome menu!" do?\n"; cout << endl; cout << "1 - add products" << endl; cout << "2 - delete products" << endl; cout << "3 - show products" << endl; cout << "0 - go back" << endl; } else { return 0; } } } return _getch(); } void menuvesstock::menu(int storeid) { bool goon = true; while (goon) { switch (menuvesstockoptions()) { case '0': goon = false; break; case '1': //saveproduct(); break; case '2': //delhoofd_stock(); break; case '3': vesstocklist(storeid); break; default: cout << "wrong choice!" << endl << endl; break; } } }
the reason being asked login because login in menuvesstockoptions() (where process user wishes do). should able fix having user login first, asking option in while loop:
menu(int storeid) { // ask user login. if it's successful, let them manage inventory etc if (userlogin()) { bool goon = true; while (goon) { // no longer handles user login. optionally pass user function switch(menuvesstockoptions()) { // before }; } } else { // user login failed. handle it: } }
Comments
Post a Comment