+ 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; }
4 Antworten
+ 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)
+ 1
which value do i have to put?
0
You can input 5 integer numbers. You get some of total
Ex: 1 2 4 5 8
Output: 20
0
This asks for an output. It can be anything.