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)
{
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;
}
#include <iostream>
usingnamespace std;
bool notUsed( int *records, int length, int input )
{
if ( length == 0 )
{
returntrue;
}
for ( int i = 0 ; i < length ; i ++)
{
if ( records[ i ] == input )
returnfalse;
}
returntrue;
}
void PrintRecords( int records[], int length )
{
for ( int i = 0 ; i < length ; i++ )
{
cout << i << ": " << records[ i ] << endl;
}
}
int main()
{
int *records = newint[ 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";
}
elseif ( 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
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.