Message-ID: <36BF6123.7CC6D3E7@bignet.net> From: John Soares X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: data verification problem Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 63 NNTP-Posting-Host: 206.67.96.153 X-Trace: news9.ispnews.com 918501185 206.67.96.153 (Mon, 08 Feb 1999 14:13:05 EDT) NNTP-Posting-Date: Mon, 08 Feb 1999 14:13:05 EDT Organization: ISPNews http://ispnews.com Date: Mon, 08 Feb 1999 14:11:47 -0800 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I need to enter an employee number that must be 9 digits, no more and no less. The way I am doing it here seems overly complicated, and does not work anyway. I need to move on to other parts of the program now. Can anyone tell me a quick easy way to verify length of data entry? Here is my function: void employee_nbr_entry(employee& e) { //this can't be too long or too short. char test_nbr[9] = " "; char ch = ' '; int count = 0; cout << "Enter 9 integer employee number: "; for (int i = 0; i < worker_nbr; ++i) { ch = getchar(); cout << "int(ch) is: " << int(ch) << endl; test_nbr[i] = ch; ++count; if (count > worker_nbr) { if ((int(ch) == 10)) { cout << endl << "nbr limited to 9 characters"; test_nbr[i] = ch; e.nbr = atol(test_nbr); return; } } if ((int(ch) == 10)) { if (count < worker_nbr) { cout << "must be at least 9 characters" << endl; cout << "enter 9 digits from scratch: " << endl; employee_nbr_entry(e); } } e.nbr = atol(test_nbr); } return; } I know there must be an easier way to do this. Any hints appreciated. John