Storing array index into another array in c++?
-
So im just trying to store an array's indexes into another array so if there are two of the same number I can show where the two indexes are located What I have: #include ...show more
-
Answer:
b[x]=i; Where are you setting the value of x? Edit: What you are doing is called searching. You don't need the b array for that. cin >> key; for (i=0; i<8; i++) if (a[i]==key) cout << " " << i; return 0; Edit: >>> "how would I later call to the 2 indexes of 7?" You didn't say anything about a later call. AND, the main point of this assignment is for you to figure things out, not ask others for a complete solution.
6JLYP2VSQVNS74W5U3XRI3OWEM at Yahoo! Answers Visit the source
Other answers
Try: #include <iostream> using namespace std; int main() { int a[8]= { 1, 2, 3, 4, 5, 7, 7, 42 }, b[8], key, x, i; cout << "Enter your key: "; cin >> key; for ( x= i= 0; i < 8; ++i ) if ( a[i] == key ) b[x++]= i; for ( i= 0; i < x; ++i ) cout << ' ' << b[i]; cout << endl; return 0; }
Jonathan
Related Q & A:
- How to post an array of complex objects (that has an array of complex objects) with jQuery?Best solution by Stack Overflow
- How to convert a char array into an int in C++?Best solution by Stack Overflow
- how can i remove an array from an array?Best solution by Stack Overflow
- Converting char array to double in C?Best solution by stackoverflow.com
- How can we get SBJSON connectionDidFinishLoading method inside array data in another class?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.