Hi everyone. I'm a c++ beginners and trying to make a simple login system for multiple users. New users can register for an account and login into the system. For my problem is about my programming system only can read the first username and password (in the first line). How to write out a command for the system to read the second user and password () second line) and third and so on... The user file will be like:
User1 Password1
User2 Password2
User3 Password3
Hope anyone here can help me. Use vector? or any other technique. Thanks a lot!
Lines 28, 32: You will never reach these statements.
Lines 28, 32, 37, 60: You're handling repetition by use of recursion. You really should be using loops. There are a couple of reasons why recursion is a poor choice. 1) When you return from a nested main, you don't know why you returned, leading to incorrect program flow. 2) In theory, you can overflow the program's stack if you recurse enough times.
edit: Thanks jlb Didn't realize recursively calling main() was not allowed.
@keskiverto
Thanks for your suggetion and I have corrected the loop with my own idea and it is going well:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
while (log >> logU >> logP ){
if (logUsername == logU && logPassword == logP){
exist = 1;
if (exist == 1){
break;
}
else{
exist = 0;
}
}
Or any suggestion to make it more better/any problem? Btw, for the "same username" problem, I think I might need to build a checking system too to avoid same username. Is it what you mean?
switches have fall through, which is a bug when you do not mean to do it, and powerful if you do mean to do it.
here is an example of it being useful:
cin >> ch;
switch(ch) //did the user want yes, no, or input junk?
{
case 'y':
case 'Y':
user_yes(); //this happens on both upper and lower case y because fall through (no break on the case)
break;
case 'n':
case 'N':
user_no();
break;
default: user_idiot();
}
it is bad if you had like
case 'y':
user_yes();
//break should go here, but it is missing
case 'n':
user_no(); //hey, this happens when they type y?! Oops: forgot the break statement!