1. ## Array question..

I have wrote this program to calculate the 5 elements of an array..
Code:
```#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>

using namespace std;

int main(int argc, char *argv[])
{
int n[5],i;

for(i=0;i<5;i++)
{
cout<<"Value for n["<<i<<"]:";
cin>>n[i];
}

for(i=0;i<5;i++)
{
cout<<i<<":"<<n[i]<<endl;
}

int sum=n[0]+n[1]+n[2]+n[3]+n[4];
cout<<"The sum is:"<<sum<<endl;

system("PAUSE");
return 0;
}```
could someone tell me (if it is) a way to calculate mora than 4 elements,,lets say the array have 100 elements..

2. >could someone tell me (if it is) a way to calculate mora than 4 elements
Yes, but it's error prone and not very scalable. Have you considered using a loop instead?
Code:
```int sum = 0;
for ( int i = 0; i < 5; i++ )
sum += n[i];```

3. Got a few warnings when I compiled this:

C:\MySource>bcc32 argc.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
argc.cpp:
Warning W8057 argc.cpp 27: Parameter 'argc' is never used in f
Warning W8057 argc.cpp 27: Parameter 'argv' is never used in f

4. You could do this.

Code:
```int n[100], i, sum;

sum = 0;

for(i = 0; i < 100; i++)
{
cout << "Value for n["<<i<<"]:";
cin >> n[i];
sum +=  n[i];
}

for(i=0; i < 100; i++)
{
cout << i << ":" << n[i] << endl;
}```
Im pretty sure thatll work...Didnt test it but wrote it up in word, hope it helps

5. Thanks for the help guys..my program works fine!

6. I was just thinking about arrays.. and then i started thinking aboot vectors.. and then I was like, "hmm.. is there a way in c++ to make multi-dimensional vectors..?" I've never seen code for this type of implementation but i think it would be a cool data structure.

7. Originally Posted by The Brain
I was just thinking about arrays.. and then i started thinking aboot vectors.. and then I was like, "hmm.. is there a way in c++ to make multi-dimensional vectors..?" I've never seen code for this type of implementation but i think it would be a cool data structure.
std::vector< std::vector<T> >

8. ahh.. a vector of vectors..

9. Wanna guess what a 12th dimension vector would look like?

10. Originally Posted by snapshooter
could someone tell me (if it is) a way to calculate mora than 4 elements,,lets say the array have 100 elements..
A possible way to do that:

Code:
```#include <numeric>
...
int n[100];
...
// Stuff 100 values into array
...
// Calculate sum of all 100 elements
int sum = std::accumulate(n,n+100,0);```

11. Wanna guess what a 12th dimension vector would look like?

Just out of curiosity.. how would you pushback( ) to let's say.. the 5th dimension of a 12 dimension vector...?

12. Very very very carefully. Basically you'll have to use an iterators to get to the 5th dimension and then use push_back() on that.

edit:
Or:

Code:
```vector < (insert other vectors) > > > > > > > > > > > > vec;
vector < (insert 4 other vectors) bleh;
vec[0][0][0][0][0].push_back(bleh);```

13. Originally Posted by Thantos
Wanna guess what a 12th dimension vector would look like?
Ack! That's hideous.

14. Code:
```template <unsigned int depth, typename type>
struct vec_gen
{
typedef std::vector < typename vec_gen<depth - 1, type>::result > result;

typedef char[depth - 1] null_protection;
};
template <typename type>
struct vec_gen<1>
{
typedef std::vector <type> result;
};```
Wanna guess what a 12th dimension vector would look like?
Like this:
Code:
`typedef typename vec_gen<12, int>::result ivec12;`

15. Cheater