Trying to assign a unique record number

I've written a function to assign a unique number to a variable in an array. I've run into a problem where it won't leave the first loop.

What it's supposed to do is take a number, go through all of the recordnumbers until it reaches the last one. If the number has been used, it stops going checking for the number, increments that number, and starts checking again. If the number hasn't been used, it assigns that number to the recordnumber variable in the mobile struct.

I'm still fairly new at C++ - doing it for college - so it's probably a blaring error.

Thankyou ^_^ My code:

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
void assignRecordNumber(details mobile[], int recordcount)

{

	int row;
	int number = 1;
	int finalnumber;

	int numberisused;

	int	donotloop1;
	int donotloop2 = 0;


	while (donotloop2 == 0)

	{

		row = 0;

		donotloop1 = 0;

		while (donotloop1 == 0)

		{

			if (mobile[row].recordnumber == number)
			{	donotloop1 = 1;
				numberisused = 1;	}

			if (row == recordcount)
				donotloop1 = 1;

			row++;

		}

		if (numberisused == 0)
		{	finalnumber = number;
			donotloop2 = 1;	}

		else
			number++;

		cout << number << endl;

	}


	mobile[recordcount].recordnumber = finalnumber;

	cout << finalnumber;

}
line 27(incorrect): if (mobile[row].recordnumber == number)

correct: if (mobile[row] == number)

Fine
recordnumber is a variable in the mobile struct
Topic archived. No new replies allowed.