0

Using a while Loop

#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; } someone pls help me to clarify the above coding using while.. as per program if num is less than or equal to 5 it will ask for the number from the user then it will add upon to the total, then num++ from 1 to 2 then it will check whether it is less than or equal to 5, then it should ask the user to enter the number right.. but it's not happening. It just asked for one time and i given as 1 then it resulted as 5. is it correct, if yes can u pls explain.

14th Oct 2020, 3:10 PM
Martin Joshwa
1 Respuesta
0
Sololearn takes all input at once. Try giving all the 5 values at once, each in a new line to avoid any errors.
14th Oct 2020, 3:13 PM
Avinesh
Avinesh - avatar