Searching Array (Help Please)

This is a discussion on Searching Array (Help Please) within the C++ Programming forums, part of the General Programming Boards category; Okay, now that I go all of my sorting of the array out of my way, I am into a ...

Searching Array (Help Please)

Okay, now that I go all of my sorting of the array out of my way, I am into a new problem with this stupid program, and I really need help ASAP please! I am trying to search the array of employees by last name and display the employee that was searched with all of their data. Could someone please help me here!!!

Oh, you started another thread. You should probably have continued your other one. I just wrote a bunch of stuff in there. Only start a new one if it is about a completely separate thing, or several weeks have passed with no activity in the thread.

In this instance you should put braces around your for loop statements so that you can see what is actually going on:

How many times is "Not Found" going to be shown? Does that make the problem obvious?
The trick is that you shouldn't use an else here. Instead, when you find the thing your after you return from the function immediately. Then if you loop ends and you're thus still inside the function, it must have failed to find the item, so...

Again you're taking an array of strings as a parameter to a function, but you have no array of strings, only an array of Employee. Same hint as last time.
Incidentally if would be great if you had used strings inside of employee instead of char arrays, but that's beside the point.

I used the chars so that I could store the spaces that the strings weren't storing inside the output. So like for the City it could be: Some Town. With the strings, it would think that Some was the City, and Town was the State...it was really annoying me.

as for the searching function, am I going about it in a right fashion, or could you help me here. I tried putting it into my class and it still is saying that data is undefined...this is annoying and I need it done by this afternoon. Could someone please give the code with a step-through of how it is supposed to be? Please?

the undefined part might refer to your use of the const to define your array size, in this case your compiler does not like it, i bet if you put in the number directly to define the size of your array that error will stop

Clearly whoever gave you this code expected you to do some work rather than doing your homework for you. Provide the name of an actual array in place of the text "ARRAY GOES HERE" and your compiler might stop moaning.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

1) You communicate with a sequence of vague whines rather than trying to formulate a real question in terms of C/C++ syntax, etc.
2) Probably this is because you cannot be bothered to even attempt formulating such a question.
3) Probably that is because you are LAZY.

Throwing up a pile of code, then expecting people to test one part of it and maybe re-write it for you is stupid. Why don't you take a few deep breaths, think about what specifically your problem is, then try and write a *seperate* *short* program to either demonstrate clearly the issue or (better yet, and I promise, the chances are good...) allowing you to experiment and explore the problem yourself, because if you cannot do that, then you cannot rationalize or abstract and should give up programming right now.

Originally Posted by grumpy

Clearly whoever gave you this code expected you to do some work rather than doing your homework for you. Provide the name of an actual array in place of the text "ARRAY GOES HERE" and your compiler might stop moaning.

*Sigh*...thank you for stating that I am lazy and can't come up with things on my own...the exclamation marks are just because I am frustrated...

I am not trying to come off as mean, I am just in a big predicament here and I really need some help on this. That is why I asked if someone could step through this for me so I can understand how a search function could work in this.

Yes, my code says that the array goes here, but I put that up here so that you guys knew where I was putting the array, which by the way wasn't working. I am not sure why my array, data[] wasn't working with it when I even put it into the class...I am trying different things, but any help would be nice.

Sorry for coming off as mean, lazy, and all that...I have been working on this program for 3 days now, and I am almost done, but I am in need of finishing this searching function...

PS.- I did figure out my sorting function, and that was so difficult, but I did get it with an algorithm help. I am just having a hard time finding what needs to be done for this search function.

I want to be able to use the data[] array because that is what is being used in my sorting function. The size variable is the size of the array, and the target variable is being used to store what is being searched for.

It would be a greatly appreciated help if someone can help. Sorry for all the confusion and being impatient! :P Not trying to sound like I am yelling here.

Can you posted the updated code please. After making suggestiong and giving hints, we need to see what changes were actually made in order to know what to suggest next. You can skip large parts that weren't changed if you like.
Edit: Sorry cross-posted.

MK27, it's not necessarily laziness. Some people have a personality type where sympathy becomes as important or more so than the actual assistance, and this leads to them being rather vague about the actual problem. Admittedly it's not productive from the point of view of most of us here, but I think you'll appreciate that most of us do better when we are happy, and for some the affect is greater than in others. Make sure your criticism is constructive I guess.
This person is trying, they're just not as good as helping themselves to be helped as some are.

Do you mean for search to be private? That means that things outside the class can't access it.
How about just putting a function prototype in the class, and then putting the definition outside, like you have with your other functions?
Organisationally, this needn't be much different from inNameeID or your other functions.

MK27, it's not necessarily laziness. Some people have a personality type where sympathy becomes as important or more so than the actual assistance, and this leads to them being rather vague about the actual problem. Admittedly it's not productive from the point of view of most of us here, but I think you'll appreciate that most of us do better when we are happy, and for some the affect is greater than in others. Make sure your criticism is constructive I guess.

Yeah I'm kind of in groucho mood, or was, all apologies...I don't have time to be compiling and decyphering this, so I just wanted to indicate there is a "better" way. All in good time I guess.

@RadethDart: would help if you indicate where/when you are being told you have these undefined variables (eg, the line number, and indicate that line).