Skip to content

Instantly share code, notes, and snippets.

@freshcutdevelopment
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freshcutdevelopment/4c85d6ff16fbcaac8ea4 to your computer and use it in GitHub Desktop.
Save freshcutdevelopment/4c85d6ff16fbcaac8ea4 to your computer and use it in GitHub Desktop.
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