Advertisement
avr39ripe

cppProductFrom1to20

Jun 28th, 2021
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     const int maxRange{ 20 };
  6.     const int minRange{ 1 };
  7.     int num;
  8.     bool correct{ false };
  9.  
  10.     uint64_t product{ 1 };
  11.  
  12.     do
  13.     {
  14.         std::cout << "Enter number from " << minRange << " to  " << maxRange << '\n';
  15.         std::cin >> num;
  16.         correct = (num >= minRange) and (num <= maxRange);
  17.  
  18.         if (!correct)
  19.         {
  20.             std::cout << "Not in range! Try again!";
  21.         }
  22.     } while (!correct);
  23.  
  24.     for (; num <= maxRange; product *= num++);
  25.     std::cout << "Product is: " << product << '\n';
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement