Załóżmy, że chcę w C++ napisać program sumujący dowolną, niepodaną wcześniej ilość liczb. Oto, co mi przychodzi do głowy:
#include
#include
using namespace std;
main()
{ int a, s;
s=0;
while(scanf("%d", &a)!=EOF) s = s + a;
cout << s;
return 0;
}
Pytanie jest takie: czy mogę jako warunek pętli while użyć cin zamiast scanf? I jak to zrobić?