What does this {total += number} mean, Why The + ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What does this {total += number} mean, Why The + ?

#include <iostream> using namespace std; int main() { int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; return 0; } please help

17th Oct 2016, 1:58 PM
wybe
7 Answers
+ 4
This is the same like total = total+ number; but shorter syntax
17th Oct 2016, 2:13 PM
Petr Hatina
Petr Hatina - avatar
+ 2
total=total+ number // sum of five numbers (num<=5)
17th Oct 2016, 4:41 PM
ravishankar v
ravishankar v - avatar
+ 2
Thanks alot
18th Oct 2016, 1:43 PM
wybe
+ 2
HI!!!! HOW ITS WORK? TOTAL+=NUMBER
24th Feb 2018, 2:21 PM
Khawaja Muhammad Sohail 26
Khawaja Muhammad Sohail 26 - avatar
0
input is 5 numbers output is sum of the numbers
17th Oct 2016, 3:46 PM
saeid242
0
total += number; Is a shortcut for: total = total + number; It's doing essentially the same thing which is adding the variable "number" to the variable "total".
17th Oct 2016, 6:03 PM
dlx
0
output will goes to total objecr
17th Oct 2016, 6:35 PM
Shahvan Ansari
Shahvan Ansari - avatar