Why won't my validation loop?

So I am making this program that checks user input for a Customer ID #. Formats that should be allowed are LLLNNNN so L = Letter and N = Number. Examples: ABC1234, BCDE2345. However if I input a wrong format I want the program to loop again to allow the user to try again. If I put in anything, it will still say that it is valid and will not loop for the user to try again. Why is that?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
include <iostream>
#include <string>
#include <cctype>
using namespace std;


//function prototype
bool TestID (char [], const int);

int main ()
{
	const int size = 8;
	char CustomerID[size];
	bool test;

	do 
	{
	//get customer id number
	cout << "Valued Customer," << endl;
	cout << "Please enter your unique ID verification." << endl;
	cout << "ID Format: LLLNNNN (L = Letter, N = Number)" << endl;
	cout << "Customer ID: ";
	cin.getline(CustomerID, size); //Use this format for capturing input that goes into an array with a determined size

	//detemine if the ID is incorrect
	test = TestID(CustomerID, size);

	if (test = true)
		cout << "That is a valid Customer ID." << endl;
	else if (test = false)
	{
		cout << "That is not the proper format of the " << endl;
		cout << "Customer ID. Please try again. " << endl;
		cout << "Here is an example ABC1234\n " << endl;
	}
	} while (test = false);

	system ("pause");
	return 0;
}

bool TestID (char ID [], const int SIZE)
{

	int count; // Loop counter 
	bool test;

 // Test the first three characters for alphabetic letters. 
 for (count = 0; count < 3; count++) //checks elements 0 through 3
 { 
	if (!isalpha(ID[count])) 
	{
	return test = false;
	}
 } 

  // Test the remaining characters for numeric digits. 
 for (count = 3; count < SIZE - 1; count++) //checks elements 3 through 7
 { 
	if (!isdigit(ID[count])) 
	 return test = false; 
 } 

 return test = true;
}
Last edited on
if (test = true)

I guess you mean if (test == true)
Thomas1965,

Yup. I totally overlooked the relational operators. Silly me. Thanks, I fixed up my code for the if statements and while loop and it works as expected.

Thanks
Topic archived. No new replies allowed.