### Help with Program

For the program I am supposed to make the each number of the array increment by the number that is given by the user. For example:
Array of the numbers [1,2,3,4,5]. The user gives increments of [1,2,3,4,5].
The array would have to be incremented by each number that is in the increments first 1 then lastly 5. I don't know how to get this to work on my program. Thank you very much.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960`` ``````#include using namespace std; int incarray(float Array[], int size, float increment[], float incanswers[]) { int i; int j; for (i = 0; i < size; i++) { incanswers[i]= Array[i] + increment[i]; } return 0; }; int main() { int end; int i; float inc[1000]; float A[1000]; float ans[1000]; cout << "Enter the size of the Array" << endl; cin >> end; cout << "Please Enter the number you want the increment to be." << endl; for (i = 0; i < end; i++) { cin >> inc[i]; if (inc[i] == 0) { break; } } cout << "Please Enter the numbers for the array" << endl; for (i = 0; i < end; i++) { cin >> A[i]; } incarray (A, end, inc, ans); cout << " " << endl; for (i = 0; i < end; i++) { cout << ans[i] << endl; } return 0; } ``````
Can you give an example of input and output?
Why does an increment input of zero break your first for loop? -- this will lead to you accessing uninitialized data (that's bad).

If I understand correct, you're saying an input of [1, 2, 3, 4, 5] and increments [1, 2, 3, 4, 5] should produce an output of [2, 4, 6, 8, 10]?

Seems to work for me...
 ``` Enter the size of the Array 5 Please Enter the number you want the increment to be. 1 2 3 4 5 Please Enter the numbers for the array 1 2 3 4 5 2 4 6 8 10```

But again, I would remove the
 ``123`` ``````if (inc[i] == 0) { break; }``````

because you don't have any logic further down to handle the loop breaking early.
The user is should be allowed to enter as many increments as they want and when they put in 0 that means it stops putting it values. But for the main program it supposed to increment the array in the array by the first increment, then the second increment, and so forth.

so if they put it 1 and 2 for the increments and the array has the values 0 and 0 in it it should output
1
1

2
2
Topic archived. No new replies allowed.