I am working on Login/Registration system. So far I am getting the error that the variable "count" is used without being initialized.
bool count;
string userId, password, id, pass;
system("cls");
cout << "\t\t\n Please enter the username and password\n\n";
cout << "Username:";
cin >> userId;
cout << "Password:";
cin >> password;
//reads info from the file
ifstream readL("record.txt");
while (readL >> id >> pass) {
if (id == userId && pass == password) {
count = true;
}
else {
count = false;
}
}
readL.close();
if (count == true) {
cout << userId << " your LOGIN is successfull.\n\n";
main();
}
else {
cout << "\nLOGING error\n\nPlease check your username and password\n\n\n";
main();
}
I have second part of the code and same system works here. `
case 1: {
bool count;
string suserId, sId, spass;
cout << "\n\nEnter the username that you remember:";
cin >> suserId;
//reads the file
ifstream f2("records.txt");
while (f2 >> sId >> spass) {
if (sId == suserId) {
count = true;
}
else {
count = false;
}
}
f2.close();
if (count == true) {
cout << "\n\n\tYour account is found!\n\nYour password is " << spass << endl << endl;
main();
}
else {
cout << "\n\n\tSorry your account is not found." << endl << endl;
main();
}
break;
}
`
The only difference that in the first case it reads two variables during the while if statement, in second only Username. But even if I am going to read only Username in the first case error is still appearing.