![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Using an array and finding the element number (subscript)I am trying to find the element number in an array. I already found the minimum number, but I need to find the element number of that minimum number. Here's the code:
CPP / C++ / C Code:
|
|
#2
|
||||
|
||||
|
Well, Tommy, it's quite obvious to me that you have already found out what element number you're looking for. If you look at your minimum function, you'll see that you have a counter (a) that ends up being used to set min to the minimum value in the array. All you need to do is grab the value of the counter from that function and print it to the screen.
Just to clarify, when I say to grab the value of the counter, I don't mean to use it to access the array. Here's what I'm saying you should do in code: CPP / C++ / C Code:
__________________
-Aaron |
|
#3
|
||||
|
||||
|
Quote:
__________________
Age is unimportant -- except in cheese |
|
#4
|
|||
|
|||
hmmmmmmmmwhy cant we just print out both:
> the minimum element > its position in array in the minimum() function itself?? as aaron said "grab" the value, may be into another variable, each time "min" is updated. later print both. wud work?? i guess so. |
|
#5
|
|||
|
|||
|
Quote:
Walt, The person I was talking about was tzuchan. I think there's an easier way than to create another function. Like creating a variable. |
|
#6
|
||||
|
||||
|
Quote:
__________________
-Aaron |
|
#7
|
||||
|
||||
|
Quote:
__________________
Age is unimportant -- except in cheese |
|
#8
|
||||
|
||||
|
That's quite true, as you could access the minimum value of the array wherever you want, but you can only return one value from the function. Just return the index of the minimum item, then display it using the index instead of the min variable.
__________________
-Aaron |
|
#9
|
|||
|
|||
|
Quote:
Isn't the index of the minimum a? If it isn't, then I must not be too bright. Are you saying to return a? I have tried "return(a)" instead of "return(min)", but this doesnt work. I have also tried "return (min[a])" and I still can't get it. You guys are making it sound easy, but for me it isnt. |
|
#10
|
||||
|
||||
|
Okay, here's what you want to do. You return the counter "a" when your function is done finding the minimum, then in main(), you can access the array with it to display the minimum. So your code would look like this...
CPP / C++ / C Code:
__________________
-Aaron |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Extra null element in an array | samtediou | MySQL / PHP Forum | 2 | 11-Dec-2003 11:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The