I'm trying to create a user-defined array using struct, create an array of contacts, and sort and search the array by both first and last name. Right now I'm trying to build the array and simply display it right now but its erroring out on me right off the bat. This is new territory for me. The only thing that is underlined in red in the code is commented with the error.
Ok I added #include <string> which took care of the underline error. Can't believe I forgot that. I'm trying to restructure the input contacts in main() but I can't get it to work.
I've tried enterContacts(contacts);enterContact(Contact[]);enterContacts(Contact contacts[]); among a few other things. Any ideas what I'm missing here? Probably something simple again.
The goal I was trying to reach was structure the code to say
Enter first name for person 1:
Enter last name for person 1:
Enter phone for person 1:
Enter first name of person 2:
and so forth as you enter names and information into the array.
Look at line 17 and line 35. What's the difference between the two ?
Also, the function declared on line 17 doesn't have a definition...a function with no definition is uneventful indeed :p
I get an error indicator under the second square bracket. "Expecting an expression." So I'm still missing something
And still no luck calling the functions in the main().
These are my current tries. enterContacts(Contact contacts[]);printContacts(Contact contacts[]);
I have been trying to get this to work and have got the enterContacts function to work. My problem now is that I can't get the printContacts function to work properly. The printContacts will only print out the last entry from the enterContacts 5 times. I want it to print out each of the contacts from the array. Any idea how to make it work that way?
Thanks for the reply cire.
I am going off the guide lines for my project by creating a user defined array. Ideally I would have the program read and append a text file but I was told I can't do that for this project. The array structure and functions are predetermined and mandatory for me to get the grade.
Its not like I'm saying here is my homework do it for me. There is either something I am missing, over looking, or obviously don't know and I'm here trying to help myself understand it. A fresh pair of eyes can usually see something that has been overlooked and a more knowledgeable coder can help me understand.
This program has made me feel like I am completely brain dead the first couple of programs for this semester were so easy I whipped them out in class, but this one, even the simplest stuff has eluded me.
Once again, there is no array in your code. Nor are there any functions in your code which deal with arrays.
enterContacts takes a reference to one contact and stores user input in it 5 times. printContacts takes a copy of one contact object and prints it out 5 times. main declares one contact object.
Add this back to where you reference the array in the main [5]
Next you want to make sure your functions match the Function prototypes.
You had them right at one point enterContacts(Contact contacts[]); printContacts(Contact contacts[]);
In your printContacts (original code) you had contacts[i].firstName
You want to mimic that in your enterContacts.
You had the basics already in place but you over thought it. Once you get past this huddle and you should be good to go. You had all the answers just not the right order.
Hey thank you desago. I have just been feeling brain dead lately and after you pointed out what I needed to do it all fell into place I've already moved pasted the printing of the array and worked through my first and last name sort. Now I'm working on the search aspect.
I'll leave this thread open if I need to ask questions about the search aspect.