-1

I need to create a program that will accept values from users (name, age, bday, etc) and save these values in an array. Pretty easy right? But my problem is I want it to be able to save more than one set of inputs. I'm thinking of using a 2d array for this.

Example:

Element 0,0 will hold the value name1, 0,1 age1, 0,2 bday1

Element 1,0 will hold the value name2, 0,1 age2, 0,2 bday3

and so on... the user must be able to input as many sets of names, ages, and bdays as possible.

Then another functionality I need is that the program must be able to ask the user to input a searchKey, then the program will loop through the values of the 2d array until it finds that searchKey.

When it finds it, the user must be able to delete the entire row.

ex. searchKey == name1.

When the program finds name1, the program must delete everything else in its row. (age1, bday1)

My question is.

  1. Is it possible to do that using arrays only?
  2. How?

Note: I'm not asking for a complete code. Just a clue on how should I do it would be greatly appreciated. Thanks!

2
  • can't you use Collections? Commented Nov 18, 2015 at 9:20
  • Using collection will be very easy to handle as compared to arrays Commented Nov 18, 2015 at 9:52

1 Answer 1

1

the user must be able to input as many sets of names, ages, and bdays as possible.

  1. Ask how many values user need to input. (get some idea from here for array)
  2. Run input logic inside a loop.

that the program must be able to ask the user to input a searchKey, then the program will loop through the values of the 2d array until it finds that searchKey.

  1. Once you complete above steps you will get idea(Update:Learn) how to do this

I would recommend you to go through some sample code from google with looping logic

Sign up to request clarification or add additional context in comments.

4 Comments

The first 1 and 2 are too limited. No user wants to determine the number of N tuples to enter. Then what; the loop ends never to allow more elements to added?
thanks @ChiefTwoPencils but this is not a concrete algorithm
Yes but..."the user must be able to input as many sets of names, ages, and bdays as possible." As possible doesn't suggest "values user need to input." The req suggests the user need not define a concrete number of loops. That negates your #2.
hmm, my bad got some wrong understanding of question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.