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
|
#include<iostream>
using namespace std;
void fillArray(int records[], int ssn, int& numberOfRecords);
void listRecords(int records[], int numberOfRecords);
bool isExist(int ssn, int records[], int numberOfRecords);
const int size=32;
int records[size];
int numberOfRecords;
int ssn;
int i;
int main()
{
cout<<"Enter a 4 digit Social Security Number. Press 0 to exit"<<endl;
cin>>ssn;
isExist(ssn, records, numberOfRecords);
fillArray(records, ssn, numberOfRecords);
listRecords(records, numberOfRecords);
if(ssn==0)
cout<<"Exiting Program."<<endl;
system("pause");
}
void fillArray(int records[], int ssn, int& numberOfRecords)
{
do
{
for(i=0;i<size;i++)
{
while(ssn>=1000&&ssn<=9999)
{
if(isExist(ssn, records, numberOfRecords)==false)
{
records[i]=ssn;
i++;
numberOfRecords=i;
cout<<"Number has been recorded"<<endl;
cin>>ssn;
}
if(isExist(ssn, records, numberOfRecords)==true)
{
cout<<"This number has already been recorded"<<endl;
cin>>ssn;
}
}
}
while((ssn<1000&&ssn>0)||(ssn>9999))
{
cin>>ssn;
}
}while(ssn!=0);
}
void listRecords(int records[], int numberOfRecords)
{
int i=0;
for(i=0;i<numberOfRecords;i++)
cout<<records[i]<<endl;
}
bool isExist(int ssn, int records[], int numberOfRecords)
{
for(i=0;i<numberOfRecords;++i)
{
while(ssn==records[i])
{
return true;
}
return false;
}
}
|