fork download
  1. // Get number from user and print next 10 even numbers. (1.01)
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5.  
  6. template<typename T>
  7. T get_input(const std::string& prompt={})
  8. {
  9. std::cout << prompt << std::flush;
  10. if (T x; std::cin >> x)
  11. return x;
  12. throw std::runtime_error("get_input: Bad input");
  13. }
  14.  
  15. int ceil_to_even(int x)
  16. {
  17. return x + std::abs(x % 2);
  18. }
  19.  
  20. void put_iota(int count, int start, int step)
  21. {
  22. for (int i = 0; i < count; i++)
  23. std::cout << start + i*step << ' ';
  24. std::cout << std::endl;
  25. }
  26.  
  27. int main()
  28. {
  29. put_iota(10, ceil_to_even(get_input<int>("Enter a number> ")), 2);
  30. }
Success #stdin #stdout 0s 5320KB
stdin
-3
stdout
Enter a number> -2 0 2 4 6 8 10 12 14 16