Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Help on self-check 2.32.

+8 votes
Inside a for loop on this problem, it says

    for (int count = MAX; count <= 1; count --) {

        number += (count * count);



Do you think this is just a typo, or is "+=" an actual operation?
asked Sep 11, 2016 in CSC 211 (F16) by Alyssa Nestor (100 points)

2 Answers

+6 votes
+= is an operator where you take the value on the left and add the value on the right to it and assign that new value to the variable on the left. For example x+=7 is the same as x=x+7.
answered Sep 11, 2016 by Jared Haeme (285 points)
+3 votes
In that problem, number += (count * count)  is equivalent to number = number + (count * count).

There are other operations like -=, *=, /=and  %= that work in a similar way!
answered Sep 12, 2016 by Jordan Peklo (100 points)