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