fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. int main()
  6. {
  7. long double pi = atan(1.)*4;
  8.  
  9. int input;
  10. while(true)
  11. {
  12. std::cout << "Please enter how many digits of PI you would like to see (Max 20): ";
  13.  
  14. if (!(std::cin >> input))
  15. return 255;
  16.  
  17. if(input > 0 && input <= 20)
  18. break;
  19.  
  20. std::cout << "That's not a valid number! Try again." << std::endl;
  21. }
  22.  
  23. std::cout << std::setprecision(input);
  24. std::cout << "Pi approximated: " << pi << std::endl;
  25. }
  26.  
Success #stdin #stdout 0s 2900KB
stdin
18
stdout
Please enter how many digits of PI you would like to see (Max 20): Pi approximated: 3.14159265358979312