avr39ripe

cppWhileLoopBasics

Jun 21st, 2021
836
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     int num{ 123456 };
  6.     int sum{ 0 };
  7.     int counter{ 5 };
  8.  
  9.     std::cout << "Start " << std::boolalpha << "counter = " << counter << " counter >=0 " << (counter >=0) << '\n';
  10.     while (counter >= 0)
  11.     {
  12.         std::cout << std::boolalpha <<  "counter = " << counter << " counter >=0 " << (counter >=0) << '\n';
  13.  
  14.         sum += num % 10;
  15.         num /= 10;
  16.  
  17.         std::cout << "sum = " << sum << " num = " << num << '\n';
  18.  
  19.         --counter;
  20.     }
  21.  
  22.     std::cout << "Finish " << std::boolalpha << "counter = " << counter << " counter >=0 " << (counter >= 0) << '\n';
  23.        
  24.     std::cout << "sum = " << sum << '\n';
  25.  
  26.     return 0;
  27. }
RAW Paste Data