Answer the question
In order to leave comments, you need to log in
How can a for loop count input?
#include <iostream>
int main()
{
int sum = 0;
// Разрешаем пользователю ввести до 10 чисел
for (int count=0; count < 10; ++count)
{
std::cout << "Enter a number to add, or 0 to exit: ";
int val;
std::cin >> val;
// Выходим из цикла, если пользователь введет 0
if (val == 0)
break;
// В противном случае, добавляем число к общей сумме
sum += val;
}
std::cout << "The sum of all the numbers you entered is " << sum << "\n";
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question