Hi guys,
I'm writing this code that allows people to sign into a system. the programme asks the user to enter their account number, and checks that it is 5 digits (since the account numbers all consist of 5 digits) but it always gives an error. whether there are 5 digits entered, or not. i thought it was because my cin buffer was somehow full. so i've tried cin.clear(), and cin.ignore(), and cin.sync(). but neither one of these seem to work. Please help!
there's the code. (this is only the sign in function. the whole code is much much bigger)
i know the reading from the file bit is not done yet, but let's get this cin problem sorted. that part is easy.
thank you all
I'm writing this code that allows people to sign into a system. the programme asks the user to enter their account number, and checks that it is 5 digits (since the account numbers all consist of 5 digits) but it always gives an error. whether there are 5 digits entered, or not. i thought it was because my cin buffer was somehow full. so i've tried cin.clear(), and cin.ignore(), and cin.sync(). but neither one of these seem to work. Please help!
there's the code. (this is only the sign in function. the whole code is much much bigger)
i know the reading from the file bit is not done yet, but let's get this cin problem sorted. that part is easy.
thank you all
Code:
void SignIn()
{
char accno [5]; // Account Number
char pw [MAX]; // Password
file2.open ("Passwords.bin", ios::out);
cin.clear();
cout<< "Account Number: ";
cin.getline(accno, 5);
cin.getline(accno, 5);
int k = strlen(accno);
cout << "k= " << k << "\n\n\n" ;
cout.flush() ;
while (k != 5)
{
// system("cls");
cin.clear();
cout<< "This account number is not correct.\n";
cout<< "Please Enter your account number again: ";
cin.getline(accno, 5);
k = strlen(accno);
cout << "k= " << k << "\n\n\n" ;
cout.flush() ;
}
system("cls");
cout<< "Password: ";
cin.getline(pw, MAX);
system("cls");
file2.seekg(0);
bool found = false;
while (!found && !file1.eof())
{
}
MainMenu();
}