+ 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; }
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.
đđ»đđ»đđ»
+ 1
Why doesn't the cin get more inputs while inside the While loop?
+ 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;
}