CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2013
    Posts
    7

    please help with c++ program question over arrays!

    I am trying to write a program that keeps track of social security numbers (SSN) of customers of a bank. I have to assume that SSN is a four-digit number (e.g., 1234. 0123 is not allowed.). When the program runs,it has to prompt that the user should enter a 4-digit SSN number to record, or 0 (zero) 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)
    {



    }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: please help with c++ program question over arrays!

    First, please use code tags when posting code. Without code tags, then code is unformatted and hard to read.
    Here is my code so far, I am kinda lost from what to do from here can anybody help explain?
    The code you posted does nothing really.

    You are to read the number, and then search the array to see if the number appears in the array. If it doesn't then you store the number in the array at some spot (usually at the spot in the array after the last element that was added). The assignment states plainly what you're supposed to do.
    can somebody please help me finish this code?
    Again, you really didn't do any coding except write some function header. You have no search loop in the isExist() function, you have no code to store the value in the array, you basically have nothing.

    But why were you able to at least write the empty function body, not knowing what to do next? Ok, so finish the internals of each of the functions that you wrote. If not, what specifically is stopping you from completing the isExist() and listRecords() functions? You are passed arguments, and regardless of the main() program, you should be able to finish those functions. Then you get main() to call these functions at the appropriate time.

    Since you need to store the number, I can see where it may get tricky since you need to keep track of where the last element was added. But in no way does searching an array for a number be that difficult (the isExist() function), and printing the values of an array (the listRecords) functions be such a stumbling block. So again, what is the specific reason why you cannot complete these rather simple functions? (given that you wrote the function header, complete with parameters).

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; June 26th, 2013 at 09:49 PM.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: please help with c++ program question over arrays!

    So again, what is the specific reason why you cannot complete these rather simple functions? (given that you wrote the function header, complete with parameters).
    Skeleton provided in the assigment?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured