Advertisement
RobertDeMilo

Условия и циклы Урок 7

Sep 9th, 2023
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int bill;
  6.     int sum = 0;
  7.  
  8.     do {
  9.         cin >> bill;
  10.         // подобное сочетание if и continue позволяет игнорировать ненужный случай
  11.         if (bill <= 0) {
  12.             continue;
  13.         }
  14.  
  15.         cout << "Income: " << bill << endl;
  16.         sum += bill;
  17.  
  18.     // признаком конца программы будет счёт ноль
  19.     } while (bill != 0);
  20.  
  21.     cout << "Total income: " << sum << endl;
  22. }
  23. **********************************************************************************************
  24.  
  25. #include <iostream>
  26. using namespace std;
  27.  
  28. int main() {
  29.     int bill;
  30.     int sum = 0;
  31.     do {
  32.         cin >> bill;
  33.  
  34.         if (bill > 0) {
  35.             cout << "Income: " << bill << endl;
  36.             sum += bill;
  37.         }
  38.     } while (bill != 0);
  39.  
  40.     cout << "Total income: " << sum << endl;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement