-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHaskellTut2.hs
29 lines (24 loc) · 1.43 KB
/
HaskellTut2.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--First I import modules before initiating the commands
import Data.List
import System.IO
--This function compares the age Int input by the user against our guards and then outputs the string next to it in quotes.
figureGrade :: Int -> String
figureGrade age
| (age == 0) || (age == 1) = "in a play-pen, "
| (age == 2) || (age == 3) = "in preschool, "
| (age > 3) && (age <= 5) = "in kindergarten, "
| (age > 5) && (age <= 11) = "in elementary school, "
| (age > 11) && (age <= 13) = "in middle school, "
| (age > 13) && (age <= 18) = "in high school, "
| (age > 18) && (age <= 75) = "at work, "
| otherwise = "sitting in a comfy chair with a nice blanket, "
{-
This is the body of the application below. I've included explanations next to each step.
-}
main = do --Begin following the commands below in order from top to bottom.
putStrLn "Who are you?" --prints a string asking the user who they are.
name <- getLine --prompts the user to type in their name and creates a value called "name"
putStrLn ("Hello, " ++ name ++ "!") --prints a string that adds the words "Hello, " (mind the spaces) to the "name" value and an exclamation point.
putStrLn "How old are you?" --prints a string asking the user how old they are.
age <- getLine --prompts the user to type in how old they are and creates a value called "age"
putStrLn ("You should be " ++ figureGrade (read age) ++ name ++ "!") --Smooshes it all together.