### Add Array Problem!

When i try to add it up, it show me a 0;
How fix this?;

 ``1234567891011121314151617181920212223`` ``````#include using namespace std; int add_arrays(int a[], int b[], int n); int main () { int b [5]={1,2,3,4,5}; int a [5] ={1,2,3,4,5}; int total= add_arrays(a,b, 5); cout << total << endl; } int add_arrays(int a[], int b[], int n) { int z = 0; for (int i = 0; i < n; i++) { z+= a[i] + b[i]; } return 0; } ``````

Can someone kinda check this one to see what wrong with it?
 ``123456789101112131415161718192021222324`` ``````#include using namespace std; int ture ( int a[], int b[], int d); int main () { int b [5]={1,2,3,4,5}; int a [5] ={1,2,3,4,5}; int total= ture(b, a, 5); cout << total << endl; } int ture ( int a[], int b[], int d) { const double NUM = 10; for (int d = 0; d < 10; d++) { if (a[d] != b[d]) { return false; } } return true; }``````
Last edited on
The initializer of `total` is zero because the value returned by the `add_arrays` function is always zero. Replace the return statement within `add_arrays`'s compound statement with `return z;` to fix the problem.

 ``1234567891011`` ``````int add_arrays(int a[], int b[], int n) { int z = 0; for (int i = 0; i < n; i++) { z+= a[i] + b[i]; } return z; }``````
Topic archived. No new replies allowed.