Arrays need help

Hello, I have a problem. I have made a program that allows the user to type in values into an array. Now I need to know how to add all these arrays together to get the value of all of them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
#include <clocale>

using namespace std;

int main(int argc, char** argv) {
	

   int numbers[7];
	
	cout << "Type in 7 numbers after each other: ";
	cout << endl;
        
	
	for (int add = 0; add < 7; add++){
		
		cin >> add [numbers];
		cout << endl;
		
		
		
	}
Last edited on
What are you having problems with?

BTW, althought line add [numbers] is legal, more usual form would be numbers[add]. It is slightly unsettling to see someone actually use something like 6[array] in their code
What do you even mean with "It is slightly unsettling to see someone actually use something like 6[array] in their code"?
add is a number. On different loop iterations it will assume values of 0, 1, ..., 6.
numbers is an array. Add those two together and your code is equivalent to this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cin >> 0[numbers];
cout << endl;
cin >> 1[numbers];
cout << endl;
cin >> 2[numbers];
cout << endl;
cin >> 3[numbers];
cout << endl;
cin >> 4[numbers];
cout << endl;
cin >> 5[numbers];
cout << endl;
cin >> 6[numbers];
cout << endl;
It is legal, but not straightforward.

You got those 7 numbers in one array. What do you need next? What your exact problem?
hi,

to get array members from user just use simple loop!

like this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>



int main() {
	
    const int array_length=7;
    int numbers[array_length];
    for(int i=0 ; i< array_length ; i++ ){
        std::cout<<"Enter Array Element [ "<<i<<" ] : ";
        std::cin>>numbers[i];
        std::cout<<"\n";
    }
		
	return 0;	
}

Topic archived. No new replies allowed.