#include <iostream>
int main()
{
int sum = 0, value = 0;
while (std::cin >> value)
sum += value;
std::cout << "Sum is: " << sum << std::endl;
return 0;
}
What is not accepting input? I do not follow what you mean.
Other than the blank lines and proper indenting the only change is in the while condition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
int main()
{
int sum = 0, value = 0;
while (std::cout << " Enter a number: " && std::cin >> value)
sum += value;
std::cout << "Sum is: " << sum << std::endl;
return 0;
}
Which produced this output in the shell program here.
Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: a
Sum is: 10
Formatted input (std::cin >> value) skips leading whitespace characters in the input buffer. It skips spaces, newlines etc. till it encounters the next non-whitespace input character and then starts reading from there onwards.