Could someone explain me this with numbers please | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Could someone explain me this with numbers please

#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; }

6th Nov 2019, 9:55 PM
Assou Sipas
Assou Sipas - avatar
4 Answers
+ 2
This program asks for any number. Num is initial 1, which is less than 5 so the program will enter the while-loop. Num is a counter, that counts the number of iterations. In the while-loop, the program asks for a number, add the number to a variable total. And increases the "num"-variable, which is not the same as "number"-variable. So this program asks 5 times a number and calculates the total of the given numbers. 1 + 2 + 3 + 4 + 5= 10 100 + 100 + 100 + 100 + 100 = 500 (Please put c++ in your tags)
6th Nov 2019, 10:07 PM
sneeze
sneeze - avatar
+ 1
which value do i have to put?
6th Nov 2019, 9:56 PM
Assou Sipas
Assou Sipas - avatar
0
You can input 5 integer numbers. You get some of total Ex: 1 2 4 5 8 Output: 20
6th Nov 2019, 10:12 PM
Jayakrishna 🇮🇳
0
This asks for an output. It can be anything.
6th Nov 2019, 10:49 PM
Jake