Last active
August 29, 2015 14:26
-
-
Save freshcutdevelopment/4c85d6ff16fbcaac8ea4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
//take sale amount and tip % | |
//compute the tip amount | |
//print out both the tip and the total amount of the bill | |
let tipAmount saleAmount tipPercentage = tipPercentage/100.00 * saleAmount | |
let totalAmount saleAmount tipPercentage = (tipAmount saleAmount tipPercentage) + saleAmount | |
let rec procInput (message:string) lines = | |
message |> Console.WriteLine | |
match Console.ReadLine() |> Double.TryParse with | |
| true,num -> if (num > 0.0) then num else procInput "enter a value greater than 0" lines | |
| false,num -> procInput message lines | |
[<EntryPoint>] | |
let main argv = | |
let saleAmount = procInput "Please enter the sale amount:" "" | |
let tipPercentage = procInput "Please enter the tip %:" "" | |
let tipAmount = tipAmount saleAmount tipPercentage | |
let total = totalAmount saleAmount tipPercentage | |
printf "tip: $%A" tipAmount | |
printf "total: $%A" total | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment