how to make my program to store each SSN

hello everybody, this is my first post on here and I need some help with my program. I know it is late notice as my HW is due tonight by 12 AM CT; I am having trouble getting the program to store each valid SSN the user enters in an array up to 32 SSNs. I tried to look at my for loop for a way around it but I cant see what is the problem. It only stores one SSN at a time.

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
 #include "stdafx.h"
#include<iostream>
using namespace std; 

bool isExist(int ssn, int records[4], int number_of_records);
void listRecords(int records[4], int number_of_records);


int _tmain(int argc, _TCHAR* argv[])
{

	int ssn=0000, number_of_records = 32, choice=1;
	int records[32] = { };

	do {
		cout << "Please enter your 4-digit SSN or Press 0 to exit.";
		
	isExist(ssn, records, number_of_records);
	if (isExist==false)
		listRecords(records, number_of_records);
	else
		isExist(ssn, records, number_of_records);
	}while (choice!=0);




	system("pause");

	
	
	
	
	
	
	
	return 0;
}

bool isExist(int ssn, int records[32], int number_of_records){

	/*int a = 0;
	number_of_records = 32;
	cin >> ssn;
	if (ssn == 0){
		cout << records[0] << records[1] << records[2];
		system("pause");
			 exit(1);
		}
	else if ((ssn < 1000) || (ssn>9999)){
		cout << "Sorry, this is not a valid SSN, plese enter another SSN or press 0 to exit" << endl;
		cin >> ssn;



	}

	else{
		records[a] = ssn;*/
		
		
		for (int a = number_of_records; a >=0;){
			cin >> ssn;
			ssn = ssn;
			if (ssn == records[a]){
				cout << "This SSN is already in the system, please enter another SSN or press 0 to exit";
				cin >> ssn;
				if (ssn == 0){
					cout << records[0];
					system("pause");
					exit(1);
					
				}

				if ((ssn < 1000)||(ssn>9999)){
					cout << "Sorry, this is not a valid SSN, plese enter another SSN " << endl;
					cin >> ssn;
				}
			}
			else if ((ssn<1000) || (ssn>9999)){
				cout << "Sorry, this is not a valid SSN, plese enter another SSN or press 0 to exit " << endl;
	
			
				
				cin >> ssn;
				if (ssn == 0){
					cout << records[32] << records[31] << records[30];
					system("pause");
					exit(1);
				}
					
			}
			else{
				//number_of_records++;
				cout << "This SSN has been entered in the database. " << endl;
				records[a] = ssn;
				a--;
				return false;
				
				
			}




		}
	}
//}
		void listRecords(int records[], int number_of_records)
		{
			//int *p;
			int a=32, ssn=1022;
			//p = &a;
			number_of_records = 32;
			
			do	{records[a] = ssn;
			a--;
			
			} while (a < number_of_records);
			

			

				
		}
Multiple things seem to be wrong, I'll try to make a list and edit it, if I have time to find more.

1.
1
2
3
isExist(ssn, records, number_of_records);
if (isExist==false)
	listRecords(records, number_of_records);

isExist is not a declared variable. Your isExist() function returns a bool value (Line 18 and Line 22), but you do not do anything with this value.

Instead, you'd want to something like this
1
2
if (!isExist(ssn, records, number_of_records))
	listRecords(records, number_of_records);


2.
1
2
3
do {
...
} while (choice != 0);

Your choice variable is never changed in this loop. If this is intended, you could do while (true), otherwise you should change your choice condition to 0 at some point inside the loop.

3.
bool isExist(int ssn, int records[32], int number_of_records) {...}//Line 40
If records is an argument, it should just be int records[] or int * records. This also applies to line 5 and 6.

4.
1
2
3
4
5
6
7
8
9
10
11
12
		void listRecords(int records[], int number_of_records)
		{
			//int *p;
			int a=32, ssn=1022;
			//p = &a;
			number_of_records = 32;
			
			do	{records[a] = ssn;
			a--;
			
			} while (a < number_of_records);		
		}

There is currently no point to passing in number_of_records to this function, because it will always just assign 32 to number_of_records.
Also, if your records array has a length of 32, records[32] does not exist because array indices start at 0.
Third, if "a" is initially 32, and you are decrementing it by 1 each time, a will ALWAYS be less than number of records, which is 32. You have an infinite loop.

5.
Not necessarily wrong, but
1
2
cin >> ssn; //Line 63
ssn = ssn;

The bold line doesn't do anything, you are assigning something to itself. doing cin is enough to store the variable.
Last edited on
I thank you very much, Hopefully your corrections will solve the problem.
also, will this solve the problem of not being able to store each valid SSN in an array?
ok I did everything that you did. I even changed the arguments for the listRecords function, but I still can't get my computer to display every valid ssn that was entered, it either enters " xxxx 0 0" or "0 0". I am trying to find the logic for this.

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "stdafx.h"
#include<iostream>
using namespace std; 

bool isExist(int ssn, int records[], int number_of_records);
void listRecords(int records[], int number_of_records, int a);


int _tmain(int argc, _TCHAR* argv[])
{

	int ssn=0000, number_of_records = 32, choice=1,a=32;
	int records[32] = { };

	do {
		cout << "Please enter your 4-digit SSN or Press 0 to exit.";
		
	isExist(ssn, records, number_of_records);
	if (!isExist(ssn, records, number_of_records))
		listRecords(records, ssn, a);
	else
		isExist(ssn, records, number_of_records);
	}while (true);




	system("pause");

	
	
	
	
	
	
	
	return 0;
}

bool isExist(int ssn, int records[], int number_of_records){

	/*int a = 0;
	number_of_records = 32;
	cin >> ssn;
	if (ssn == 0){
		cout << records[0] << records[1] << records[2];
		system("pause");
			 exit(1);
		}
	else if ((ssn < 1000) || (ssn>9999)){
		cout << "Sorry, this is not a valid SSN, plese enter another SSN or press 0 to exit" << endl;
		cin >> ssn;



	}

	else{
		records[a] = ssn;*/
		
		
		for (int a = number_of_records; a >=0;){
			cin >> ssn;
			ssn = ssn;
			if (ssn == records[a]){
				cout << "This SSN is already in the system, please enter another SSN or press 0 to exit";
				cin >> ssn;
				if (ssn == 0){
					cout << records[32]<<records[31];
					system("pause");
					exit(1);
					
				}

				if ((ssn < 1000)||(ssn>9999)){
					cout << "Sorry, this is not a valid SSN, plese enter another SSN " << endl;
					cin >> ssn;
				}
			}
			else if ((ssn<1000) || (ssn>9999)){
				cout << "Sorry, this is not a valid SSN, plese enter another SSN or press 0 to exit " << endl;
	
			
				
				cin >> ssn;
				if (ssn == 0){
					cout << records[32] << records[31] << records[30];
					system("pause");
					exit(1);
				}
					
			}
			else{
				//number_of_records++;
				cout << "This SSN has been entered in the database. " << endl;
				records[a] = ssn;
				a--;
				return false;
				
				
			}




		}
	}
//}
		void listRecords(int records[], int ssn,int a)
		{
			//int *p;
			a = 32;
			//p = &a;
			;
			
			do	{records[a] = ssn;
			a--;
			
			} while (a >0);
			

			

				
		}
Topic archived. No new replies allowed.