New course! Every coder should learn Generative AI!
Try a free lesson0
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
7 Answers
+ 4
This is the same like total = total+ number;
but shorter syntax
+ 2
total=total+ number // sum of five numbers (num<=5)
+ 2
Thanks alot
+ 2
HI!!!!
HOW ITS WORK?
TOTAL+=NUMBER
0
input is 5 numbers output is sum of the numbers
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".
0
output will goes to total objecr