0

How to assign/swap a sum to a variable in a loop?

If I add two numbers (let's say x + y) and want to make the sum of that the new x so that the result becomes the x in each iteration of the loop, how can I do that? I assign x = 1 at the beginning for starting off, how do I replace that with the sum of x + y?

6th May 2019, 12:54 PM
terry
terry - avatar
3 Respuestas
+ 1
x = x + y Or x += y
6th May 2019, 12:59 PM
Maneren
Maneren - avatar
+ 1
for(int i = 0; i < y; ++i) x++;
6th May 2019, 1:08 PM
Anna
Anna - avatar
0
Thank you! Problem solved :)
6th May 2019, 2:22 PM
terry
terry - avatar