+ 3

Why it is multiplying with 5 ? There is no "*".

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

7th Jul 2019, 3:59 AM
Ankit Tiwari
Ankit Tiwari - avatar
4 RĂ©ponses
+ 22
This is because in ur program while loop works for 5 times and do addition 5 times (total+=number). And we know adding a number five times is same as multiplying it with 5. đŸ‘đŸ»đŸ‘đŸ»đŸ‘đŸ»
7th Jul 2019, 8:02 AM
Tushar
Tushar - avatar
+ 1
Why doesn't the cin get more inputs while inside the While loop?
7th Jul 2019, 4:32 AM
Eltan Sam
Eltan Sam - avatar
+ 1
#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; }
14th Jul 2019, 12:58 PM
Mg Wotson
Mg Wotson - avatar