Can somebody please help with c++ code on arrays!

I am trying to write a program that keeps track of social security numbers of customers I have to assume that its a four-digit number. When the program runs,it has to prompt that the user should enter a 4-digit number to record, or 0 to exit.

The program also needs to be able to give an error message if a certain number is entered more than once.

After all the numbers have been saved and you finally end it by pressing 0, it needs to be able to output all the entered SSN's.



Here is my code so far, I am kinda lost from what to do from here can anybody help explain? not sure how to approach the rest :( can somebody please help me finish this code?


#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

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

int main()
{
int records[32];
cout << "Please enter number or 0";




system("pause");
return 0;

}


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

}

void listRecords(int records[], int numberOfRecords)
{



}
Last edited on
what exactly is causing you trouble here?
getting user input? or adding to the array?

im not exactly an experienced programmer but what i would do ( besides using a vector ) would be to add a counter that keeps track of the amount of inputs into array.
this would let you make a loop to display them and check them easier. (i suppose thats what number of Records is now that i look closer att it )

for example:
1
2
3
4
5
6
 void listRecords( int records[], int length )
{
for ( int i = 0 ; i < length ; i++ )
{
cout << i << ": " << records[ i ] << endl;
}

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
#include <iostream>

using namespace std;

bool notUsed( int *records, int length, int input )
{
    if ( length == 0 )
    {
        return true;
    }


    for ( int i = 0 ; i < length ; i ++)
    {
        if ( records[ i ] == input )
            return false;
    }
    return true;
}
void PrintRecords( int records[], int length )
{
    for ( int i = 0 ; i < length ; i++ )
    {
        cout << i << ": " << records[ i ] << endl;
    }
}

int main()
{
    int *records = new int[ 32 ];
    int length = 0;
    int input = 1;

    cout << "Welcome to the bank of Identity Theft, Please Enter SSNs of other people \n:";
    while( input != 0 && length < 32 )
    {
        cin >> input;

        if( input > 999 && input < 10000 )
        {
            if ( notUsed( records, length, input ) )
            {
                records[ length ] = input;
                length++;
            }
            else
                cout << "That number has already been used, you cant steal an identity twice silly";
        }
        else if ( input != 0 )
            cout << "Please enter a 4 digit number";

        cout << ":";
    }
    PrintRecords( records, length );
   delete [] records;
    return 0;
}


this is what i came up with, i made the Array into a pointer as well
EDIT: if more skilled people see a flaw in what i did or a better way to do it, please tell me :D
Last edited on
Your program is suffering from an acute case of malnutrition. Main() has no means of getting the required information and the two functions (bool and void) are empty of definitions. Firstly edit your post to place code tags round( <> ) it to make it easier to read and give it line numbers.
Next add a std:cin to main () below std::cout to provide the information you intend to place in the records[] array. Fill in the bodies of the two functions with their required definitions. You also need to give some thought to how you intend to check for and eliminate duplicates.
Post your amended code again if you need further assistance.
Topic archived. No new replies allowed.