How to stop a while loop

前端 未结 5 1769
醉梦人生
醉梦人生 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:11

    You are trying to check for the username and password from the user and compare with all the usernames and passwords in the file.
    Your approach seems fine. But you are printing "Invalid username..." after each comparison, not comparing all the usernames in the file. Hence move this output outside else block and place it in the while loop.

    infile checks each line separately.

    And also check the end of file.If the username and password are not found till the end of file, then print "Invald username" and provide the user to enter another set of name and password

    Hope this helps!!

提交回复
热议问题