Laurand Osmeni

Let's build a faster web.


How do I calculate using loop in C++.

Lets loop by asking a user to enter 10 times the numbers and then the code will calculate them.

Creating a variable landi with the value 1.

int landi = 1;

Now storing the sum variable with default value 0. The sum will calculate and get the total of all entered numbers.

int sum = 0;

Variable numbers for user is input.

int numbers;

Validate while landi less and equal to 10.

landi <= 10;

User is input to enter integers ten times.

cin >> numbers;

The sum variable will add and count each input entered by the user.

sum = sum + numbers;

Increase add by one.

landi ++;

Once the loop ends, calculate and print on the screen.

cout << "The sum of the numbers is: " << sum << endl;

Isn't this the easiest calculator ever? .

loop calculation C++
How do I calculate with loop in C++.
#include <iostream> using namespace std; int main () { int landi = 1; int sum = 0; int numbers; while(landi <= 10) { cin >> numbers; sum = sum + numbers; landi ++; } cout << "The sum of the numbers is: " << sum << endl; return 0; }

Feel free to use the code.

Last update .

Navigate between pages.