fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int P=0, b;
  6. while (1){ //1 всегда истинна
  7. cin>>b;
  8. if (b<0) continue;
  9. if (b==0) break; //если введен 0, выходим из цикла
  10. P+=b;
  11. }
  12. cout<<"P="<<P<<endl;
  13. return 0;
  14. }
Success #stdin #stdout 0s 4356KB
stdin
-7 8 0
stdout
P=8