How to stop a while loop

前端 未结 5 1873
醉梦人生
醉梦人生 2021-01-14 14:41

This while loop never ends. For example, when i enter a wrong password it will keep on going to the \"incorrect password\" part over and over again.

Logo();
         


        
5条回答
  •  误落风尘
    2021-01-14 15:01

    move the cout and cin statements inside the while loop:

    else 
    {
    
        while (username != user)
        {
            cout << endl << endl << endl;
            cout << "           Please enter username: ";
            cin >> user;
            cout << "           Please enter password: ";
            cin >> pass;
            inFile >> username >> password;
    
            if (user == username && pass == password)
            {
                cout << endl;
                cout << "Welcome to CherryLunch!" << endl;
    
                system("pause");
                system("cls");
    
                MainMenu();
    
            }
            else
            {           
                cout << endl;
                cout << "           Invalid Username or Password!" << endl << endl;
                system("pause");
                system("cls");
            }
        }
    }
    inFile.close(); 
    

提交回复
热议问题