CLI interface + restructuration + precision fixes Fermat Factorization

This commit is contained in:
2026-01-11 17:58:36 +01:00
parent ada11a25d2
commit 6689ff8ae2
11 changed files with 117 additions and 50 deletions

25
app/Utils.hs Normal file
View File

@@ -0,0 +1,25 @@
module Utils (askNumber, askChoice) where
import Text.Read (readMaybe)
import System.Exit (exitSuccess)
-- Ask user for an integer > 1, or exit on invalid input
askNumber :: String -> IO Integer
askNumber s = do
putStrLn s
input <- getLine
case readMaybe input of
Just n | n > 1 -> return n
_ -> do
putStrLn "Not a valid integer"
exitSuccess
askChoice :: Int -> IO Int
askChoice maxChoice = do
putStrLn "Enter your choice:"
input <- getLine
case readMaybe input of
Just n | n >= 1 && n <= maxChoice -> return n
_ -> do
putStrLn "Invalid choice"
exitSuccess