What is wrong in my code?

#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
for(int i = 0; i < n ; i++){
int a[8];
cin >> a[8];
int sum;
for(int i = 0; i < 8 ; i++){
sum = 0;
sum = sum + a[i];
cout<<sum<<endl;
}

}

}

Mistake is in line 8.
You can’t cin all the elements of array at once .
To correct it you need to remove line 8 and use a for loop to get elements of array from user.
Also you should use different variables for nested loops.
Sum variable should be initialized right at the place where it is declared in this code.

u can write the code as follows:

#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
for(int i = 0; i < n ; i++){
int a[8];
int sum = 0;
for(int j = 0; j < 8 ; j++){
cin >> a[j];
sum = sum + a[j];
}
cout<<sum<<endl;
}
}