Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.